Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
eefc851af5 | ||
|
5ab294bfa8 | ||
|
16cd697457 | ||
|
60ff52a6e4 | ||
|
cae9dc0641 | ||
|
ef41b0c59a | ||
|
772bf4e9ae | ||
|
c7be57824a |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
CSV.pro.user
|
46
CSV.pro
Normal file
46
CSV.pro
Normal file
@ -0,0 +1,46 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-07-10T12:35:18
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += core gui qml quick widgets
|
||||
TEMPLATE = app
|
||||
|
||||
TARGET = CSV
|
||||
CONFIG += c++11
|
||||
CONFIG += j4
|
||||
CONFIG -= console
|
||||
|
||||
SOURCES += main.cpp \
|
||||
svimage.cpp \
|
||||
svworker.cpp \
|
||||
svprocessor.cpp \
|
||||
svkernelv1.cpp \
|
||||
svkernelv2.cpp \
|
||||
svimageprovider.cpp \
|
||||
svpoint.cpp \
|
||||
svcurve.cpp \
|
||||
svsimplepoint.cpp \
|
||||
svfigure.cpp \
|
||||
svobject.cpp
|
||||
|
||||
HEADERS += \
|
||||
svimage.h \
|
||||
svworker.h \
|
||||
svprocessor.h \
|
||||
svabstractkernel.h \
|
||||
svkernelv1.h \
|
||||
svkernelv2.h \
|
||||
svimageprovider.h \
|
||||
svpoint.h \
|
||||
svcurve.h \
|
||||
svsimplepoint.h \
|
||||
svfigure.h \
|
||||
svobject.h
|
||||
|
||||
RESOURCES += \
|
||||
resource.qrc
|
||||
|
||||
OTHER_FILES += \
|
||||
Main.qml
|
225
Main.qml
Normal file
225
Main.qml
Normal file
@ -0,0 +1,225 @@
|
||||
import QtQuick 2.2
|
||||
import QtQuick.Window 2.1
|
||||
import QtQuick.Controls 1.1
|
||||
|
||||
ApplicationWindow {
|
||||
id: mainWindow
|
||||
visible: true
|
||||
width: 800
|
||||
height: 600
|
||||
|
||||
statusBar: StatusBar {
|
||||
Row {
|
||||
Label {
|
||||
id: statusBarState
|
||||
text: "In Progress"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: processor
|
||||
onFinished: {
|
||||
statusBarState.text = "Ready " + elapsedTime;
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
|
||||
Item {
|
||||
id: leftColumn
|
||||
width: 200
|
||||
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.top: parent.top
|
||||
anchors.right: rightColumn.left
|
||||
anchors.left: parent.left
|
||||
|
||||
Component {
|
||||
id: slider
|
||||
|
||||
Item {
|
||||
property alias title: sliderTitle.text
|
||||
property alias from: sliderSlider.minimumValue
|
||||
property alias to: sliderSlider.maximumValue
|
||||
property alias step: sliderSlider.stepSize
|
||||
property string name: ''
|
||||
|
||||
height: 50
|
||||
|
||||
Text {
|
||||
id: sliderTitle
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.leftMargin: 15
|
||||
anchors.rightMargin: 10
|
||||
anchors.topMargin: 10
|
||||
text: ""
|
||||
}
|
||||
|
||||
Text {
|
||||
id: sliderValue
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: sliderSlider.top
|
||||
text: sliderSlider.value
|
||||
}
|
||||
|
||||
Slider {
|
||||
id: sliderSlider
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
anchors.leftMargin: 10
|
||||
anchors.rightMargin: 10
|
||||
stepSize: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.bottom: renderButton.top
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
|
||||
Loader {
|
||||
id: windowSize
|
||||
sourceComponent: slider
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
onLoaded: {
|
||||
windowSize.item.title = "Window Size"
|
||||
windowSize.item.from = 0;
|
||||
windowSize.item.to = 10;
|
||||
windowSize.item.step = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: matchSize
|
||||
sourceComponent: slider
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
onLoaded: {
|
||||
matchSize.item.title = "Match Size"
|
||||
matchSize.item.from = 0;
|
||||
matchSize.item.to = 10;
|
||||
matchSize.item.step = 1;
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: errorLevel
|
||||
sourceComponent: slider
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
onLoaded: {
|
||||
errorLevel.item.title = "Error Level"
|
||||
errorLevel.item.from = 0;
|
||||
errorLevel.item.to = 10;
|
||||
errorLevel.item.step = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: renderButton
|
||||
//anchors.bottom: parent.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 10
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "Render"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
id: rightColumn
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.top: parent.top
|
||||
anchors.right: parent.right
|
||||
anchors.left: leftColumn.right
|
||||
TabView {
|
||||
anchors.fill: parent
|
||||
Tab {
|
||||
id: imageView
|
||||
title: "Image View"
|
||||
Item {
|
||||
Flickable {
|
||||
anchors.fill: parent
|
||||
contentWidth: image.width
|
||||
contentHeight: image.height
|
||||
interactive: true
|
||||
anchors.margins: 2
|
||||
clip: true
|
||||
|
||||
Item {
|
||||
Image {
|
||||
id: image
|
||||
source: ""
|
||||
smooth: false
|
||||
}
|
||||
Connections {
|
||||
target: processor
|
||||
onFinished: {
|
||||
image.source = "image://images/result";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Tab {
|
||||
id: leftImageView
|
||||
title: "Left Image"
|
||||
|
||||
Item {
|
||||
Flickable {
|
||||
anchors.fill: parent
|
||||
contentWidth: image.width
|
||||
contentHeight: image.height
|
||||
interactive: true
|
||||
anchors.margins: 2
|
||||
clip: true
|
||||
|
||||
Item {
|
||||
Image {
|
||||
id: leftImage
|
||||
source: "image://images/left"
|
||||
smooth: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Tab {
|
||||
id: rightImageView
|
||||
title: "Right Image"
|
||||
|
||||
Item {
|
||||
Flickable {
|
||||
anchors.fill: parent
|
||||
contentWidth: image.width
|
||||
contentHeight: image.height
|
||||
interactive: true
|
||||
anchors.margins: 2
|
||||
clip: true
|
||||
|
||||
Item {
|
||||
Image {
|
||||
id: rightImage
|
||||
source: "image://images/right"
|
||||
smooth: false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
-include ../makefile.init
|
||||
|
||||
RM := rm -rf
|
||||
|
||||
# All of the sources participating in the build are defined here
|
||||
-include sources.mk
|
||||
-include src/subdir.mk
|
||||
-include subdir.mk
|
||||
-include objects.mk
|
||||
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
ifneq ($(strip $(C++_DEPS)),)
|
||||
-include $(C++_DEPS)
|
||||
endif
|
||||
ifneq ($(strip $(C_DEPS)),)
|
||||
-include $(C_DEPS)
|
||||
endif
|
||||
ifneq ($(strip $(CC_DEPS)),)
|
||||
-include $(CC_DEPS)
|
||||
endif
|
||||
ifneq ($(strip $(CPP_DEPS)),)
|
||||
-include $(CPP_DEPS)
|
||||
endif
|
||||
ifneq ($(strip $(CXX_DEPS)),)
|
||||
-include $(CXX_DEPS)
|
||||
endif
|
||||
ifneq ($(strip $(C_UPPER_DEPS)),)
|
||||
-include $(C_UPPER_DEPS)
|
||||
endif
|
||||
endif
|
||||
|
||||
-include ../makefile.defs
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
|
||||
# All Target
|
||||
all: CSV
|
||||
|
||||
# Tool invocations
|
||||
CSV: $(OBJS) $(USER_OBJS)
|
||||
@echo 'Building target: $@'
|
||||
@echo 'Invoking: GCC C++ Linker'
|
||||
g++ -o "CSV" $(OBJS) $(USER_OBJS) $(LIBS)
|
||||
@echo 'Finished building target: $@'
|
||||
@echo ' '
|
||||
|
||||
# Other Targets
|
||||
clean:
|
||||
-$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(CPP_DEPS)$(EXECUTABLES)$(CXX_DEPS)$(C_UPPER_DEPS) CSV
|
||||
-@echo ' '
|
||||
|
||||
.PHONY: all clean dependents
|
||||
.SECONDARY:
|
||||
|
||||
-include ../makefile.targets
|
@ -1,8 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
USER_OBJS :=
|
||||
|
||||
LIBS := -lopencv_core -lpthread -lboost_system -lpcl -lpcl_visualization -lopencv_imgproc -lopencv_highgui -lopencv_legacy
|
||||
|
@ -1,27 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
O_SRCS :=
|
||||
CPP_SRCS :=
|
||||
C_UPPER_SRCS :=
|
||||
C_SRCS :=
|
||||
S_UPPER_SRCS :=
|
||||
OBJ_SRCS :=
|
||||
ASM_SRCS :=
|
||||
CXX_SRCS :=
|
||||
C++_SRCS :=
|
||||
CC_SRCS :=
|
||||
OBJS :=
|
||||
C++_DEPS :=
|
||||
C_DEPS :=
|
||||
CC_DEPS :=
|
||||
CPP_DEPS :=
|
||||
EXECUTABLES :=
|
||||
CXX_DEPS :=
|
||||
C_UPPER_DEPS :=
|
||||
|
||||
# Every subdirectory with source files must be described here
|
||||
SUBDIRS := \
|
||||
src \
|
||||
|
@ -1,36 +0,0 @@
|
||||
################################################################################
|
||||
# Automatically-generated file. Do not edit!
|
||||
################################################################################
|
||||
|
||||
# Add inputs and outputs from these tool invocations to the build variables
|
||||
CPP_SRCS += \
|
||||
../src/SvImage.cpp \
|
||||
../src/SvMain.cpp \
|
||||
../src/SvMultithreadProcessor.cpp \
|
||||
../src/SvProcessorV1.cpp \
|
||||
../src/SvProcessorV2.cpp
|
||||
|
||||
OBJS += \
|
||||
./src/SvImage.o \
|
||||
./src/SvMain.o \
|
||||
./src/SvMultithreadProcessor.o \
|
||||
./src/SvProcessorV1.o \
|
||||
./src/SvProcessorV2.o
|
||||
|
||||
CPP_DEPS += \
|
||||
./src/SvImage.d \
|
||||
./src/SvMain.d \
|
||||
./src/SvMultithreadProcessor.d \
|
||||
./src/SvProcessorV1.d \
|
||||
./src/SvProcessorV2.d
|
||||
|
||||
|
||||
# Each subdirectory must supply rules for building sources it contributes
|
||||
src/%.o: ../src/%.cpp
|
||||
@echo 'Building file: $<'
|
||||
@echo 'Invoking: GCC C++ Compiler'
|
||||
g++ -std=c++11 -I/usr/include/pcl-1.7 -I/usr/include/vtk-5.8/ -I/usr/include/eigen3 -O3 -Wall -c -fmessage-length=0 -pthread -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
|
||||
@echo 'Finished building: $<'
|
||||
@echo ' '
|
||||
|
||||
|
14
cl/kernel.cl
Normal file
14
cl/kernel.cl
Normal file
@ -0,0 +1,14 @@
|
||||
__kernel void ProcessLine(__global const float* a, __global const float* b, __global float* c, int iNumElements)
|
||||
{
|
||||
// get index into global data array
|
||||
int iGID = get_global_id(0);
|
||||
|
||||
// bound check (equivalent to the limit on a 'for' loop for standard/serial C code
|
||||
if (iGID >= iNumElements)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// add the vector elements
|
||||
c[iGID] = a[iGID] + b[iGID];
|
||||
}
|
BIN
img/left1.png
Normal file
BIN
img/left1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 222 KiB |
BIN
img/left4.png
BIN
img/left4.png
Binary file not shown.
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.1 MiB |
BIN
img/right1.png
Normal file
BIN
img/right1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 215 KiB |
BIN
img/right4.png
BIN
img/right4.png
Binary file not shown.
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.1 MiB |
39
main.cpp
Normal file
39
main.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <QApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlComponent>
|
||||
#include <QQmlContext>
|
||||
#include <QPixmap>
|
||||
|
||||
#include "svimage.h"
|
||||
#include "svprocessor.h"
|
||||
#include "svimageprovider.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication a(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
SvImageProvider imageProvider;
|
||||
|
||||
QImage imgLeft("../CSV/img/left1.png");
|
||||
QImage imgRight("../CSV/img/right1.png");
|
||||
QImage imgStereo(imgLeft.width(), imgLeft.height(), QImage::Format_RGB32);
|
||||
|
||||
SvImage left(imgLeft);
|
||||
SvImage right(imgRight);
|
||||
SvImage stereo(imgStereo);
|
||||
|
||||
SvProcessor proc(&left, &right, &stereo, 4, 2);
|
||||
|
||||
imageProvider.addImage("left", &left);
|
||||
imageProvider.addImage("right", &right);
|
||||
imageProvider.addImage("result", &stereo);
|
||||
|
||||
engine.addImageProvider("images", &imageProvider);
|
||||
engine.load(QUrl(QStringLiteral("qrc:///Main.qml")));
|
||||
engine.rootContext()->setContextProperty("processor", &proc);
|
||||
|
||||
proc.start();
|
||||
|
||||
return a.exec();
|
||||
}
|
7
resource.qrc
Normal file
7
resource.qrc
Normal file
@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file>Main.qml</file>
|
||||
<file>img/left4.png</file>
|
||||
<file>img/right4.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* SvImage.cpp
|
||||
*
|
||||
* Created on: 27 июня 2014 г.
|
||||
* Author: andrey
|
||||
*/
|
||||
|
||||
#include "SvImage.h"
|
||||
|
||||
int SvImage::getPixel(int x, int y, int channel = -1) {
|
||||
if (y >= this->image->rows || y < 0 || x >= this->image->cols || x < 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uchar* pixel = this->image->ptr(y, x);
|
||||
uchar value;
|
||||
|
||||
if (channel == -1 || channel > 2) {
|
||||
value = 0.299 * pixel[0] + 0.587 * pixel[1] + 0.114 * pixel[2];
|
||||
} else {
|
||||
value = pixel[channel];
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
int SvImage::getPixelHue(int x, int y) {
|
||||
uchar* pixel = this->image->ptr(y, x);
|
||||
if (x >= 0 && x < this->image->cols && y >= 0 && y < this->image->rows) {
|
||||
return abs(pixel[1] - pixel[0]) + abs(pixel[2] - pixel[1]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SvImage::getPixelValue(int x, int y) {
|
||||
uchar* pixel = this->image->ptr(y, x);
|
||||
if (x >= 0 && x < this->image->cols && y >= 0 && y < this->image->rows) {
|
||||
return (pixel[0] + pixel[1] + pixel[2])/3;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SvImage::putPixel(int x, int y, int value)
|
||||
{
|
||||
uchar* data;
|
||||
|
||||
if (x >= 0 && x < this->image->cols && y >= 0 && y < this->image->rows) {
|
||||
data = this->image->ptr(y, x);
|
||||
data[0] = value;
|
||||
}
|
||||
}
|
||||
|
||||
int SvImage::getHeight() {
|
||||
return this->image->rows;
|
||||
}
|
||||
|
||||
int SvImage::getWidth() {
|
||||
return this->image->cols;
|
||||
}
|
||||
|
||||
Mat& SvImage::getCvMatrix() {
|
||||
return *this->image;
|
||||
}
|
||||
|
||||
SvImage::SvImage(Mat& image) {
|
||||
this->image = ℑ
|
||||
}
|
||||
|
||||
SvImage::~SvImage() {
|
||||
|
||||
}
|
||||
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* SvImage.h
|
||||
*
|
||||
* Created on: 27 июня 2014 г.
|
||||
* Author: andrey
|
||||
*/
|
||||
|
||||
#ifndef SVIMAGE_H_
|
||||
#define SVIMAGE_H_
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
class SvImage {
|
||||
|
||||
protected:
|
||||
Mat* image;
|
||||
|
||||
public:
|
||||
int getPixel(int x, int y, int channel);
|
||||
int getPixelHue(int x, int y);
|
||||
int getPixelValue(int x, int y);
|
||||
void putPixel(int x, int y, int val);
|
||||
|
||||
int getHeight();
|
||||
int getWidth();
|
||||
Mat& getCvMatrix();
|
||||
|
||||
SvImage(Mat& image);
|
||||
virtual ~SvImage();
|
||||
};
|
||||
|
||||
#endif /* SVIMAGE_H_ */
|
102
src/SvMain.cpp
102
src/SvMain.cpp
@ -1,102 +0,0 @@
|
||||
//============================================================================
|
||||
// Name : CSV.cpp
|
||||
// Author : Andrey
|
||||
// Version :
|
||||
// Copyright : Your copyright notice
|
||||
// Description : Computer Stereo Vision in C++, Ansi-style
|
||||
//============================================================================
|
||||
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include "SvImage.h"
|
||||
#include "SvProcessorV1.h"
|
||||
#include "SvProcessorV2.h"
|
||||
#include <thread>
|
||||
//#include <pcl/point_cloud.h>
|
||||
//#include <pcl/point_types.h>
|
||||
//#include <pcl/visualization/pcl_visualizer.h>
|
||||
//#include <vtkRenderWindow.h>
|
||||
//#include <pcl/visualization/cloud_viewer.h>
|
||||
//#include <pcl/filters/statistical_outlier_removal.h>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
void CallBackFunc(int event, int x, int y, int flags, void* userdata)
|
||||
{
|
||||
if (event == EVENT_LBUTTONDOWN ) {
|
||||
|
||||
} else if ( event == EVENT_RBUTTONDOWN ) {
|
||||
|
||||
} else if ( event == EVENT_MBUTTONDOWN ) {
|
||||
|
||||
} else if ( event == EVENT_MOUSEMOVE ) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
Mat matLeft = imread("img/left8.png", 1);
|
||||
Mat matRight = imread("img/right8.png", 1);
|
||||
Mat matStereo(Mat::zeros(matLeft.rows, matLeft.cols, CV_8U));
|
||||
|
||||
SvImage left(matLeft);
|
||||
SvImage right(matRight);
|
||||
SvImage stereo(matStereo);
|
||||
|
||||
int line = 0;
|
||||
|
||||
SvProcessorV2 proc[4];
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
proc[i].setLeftImage(left);
|
||||
proc[i].setRightImage(right);
|
||||
}
|
||||
|
||||
while (line < stereo.getHeight()) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (line < stereo.getHeight() && !proc[i].isActive()) {
|
||||
proc[i].run(stereo, line++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//pcl::PointXYZRGB point;
|
||||
//pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGB>);
|
||||
//pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZRGB>);
|
||||
|
||||
/*cloud->resize(stereo.getHeight() * stereo.getWidth());
|
||||
|
||||
for (int y = 0; y < stereo.getHeight(); y++) {
|
||||
for (int x = 0; x < stereo.getWidth(); x++) {
|
||||
int i = stereo.getWidth() * y + x;
|
||||
int value = stereo.getPixel(x, y, 0);
|
||||
if (value) {
|
||||
cloud->points[i].x = (x - (stereo.getWidth() / 2.0))/100.0;
|
||||
cloud->points[i].y = (-y + (stereo.getHeight() / 2.0))/100.0;
|
||||
cloud->points[i].z = (-stereo.getPixel(x, y, 0) * 6.0)/100.0;
|
||||
|
||||
cloud->points[i].r = left.getPixel(x, y, 2);
|
||||
cloud->points[i].g = left.getPixel(x, y, 1);
|
||||
cloud->points[i].b = left.getPixel(x, y, 0);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
/*
|
||||
pcl::StatisticalOutlierRemoval<pcl::PointXYZRGB> sor;
|
||||
sor.setInputCloud(cloud);
|
||||
sor.setMeanK(50);
|
||||
sor.setStddevMulThresh(1.0);
|
||||
sor.filter(*cloud_filtered);
|
||||
*/
|
||||
|
||||
/*pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");
|
||||
viewer.showCloud(cloud);
|
||||
while (!viewer.wasStopped ())
|
||||
{
|
||||
}*/
|
||||
|
||||
imshow("Display Image", stereo.getCvMatrix());
|
||||
//setMouseCallback("Display Image", CallBackFunc, NULL);
|
||||
waitKey();
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* SvMultithreadProcessor.cpp
|
||||
*
|
||||
* Created on: 09 июля 2014 г.
|
||||
* Author: andrey
|
||||
*/
|
||||
|
||||
#include "SvMultithreadProcessor.h"
|
||||
|
||||
SvMultithreadProcessor::SvMultithreadProcessor(SvImage& left, SvImage& right) {
|
||||
m_left = &left;
|
||||
m_right = &right;
|
||||
m_stereo = NULL;
|
||||
m_line = 0;
|
||||
}
|
||||
|
||||
SvMultithreadProcessor::SvMultithreadProcessor() {
|
||||
|
||||
}
|
||||
|
||||
int SvMultithreadProcessor::run(SvImage& stereo, int line) {
|
||||
m_stereo = &stereo;
|
||||
m_line = line;
|
||||
m_thread = std::thread(&SvMultithreadProcessor::process, this);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SvMultithreadProcessor::process() {
|
||||
exec();
|
||||
m_thread.detach();
|
||||
}
|
||||
|
||||
void SvMultithreadProcessor::exec() {
|
||||
|
||||
}
|
||||
|
||||
SvMultithreadProcessor::~SvMultithreadProcessor() {
|
||||
|
||||
}
|
||||
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* SvMultithreadProcessor.h
|
||||
*
|
||||
* Created on: 09 июля 2014 г.
|
||||
* Author: andrey
|
||||
*/
|
||||
|
||||
#ifndef SVMULTITHREADPROCESSOR_H_
|
||||
#define SVMULTITHREADPROCESSOR_H_
|
||||
|
||||
#include <thread>
|
||||
#include "SvImage.h"
|
||||
|
||||
class SvMultithreadProcessor {
|
||||
|
||||
protected:
|
||||
SvImage* m_left;
|
||||
SvImage* m_right;
|
||||
SvImage* m_stereo;
|
||||
|
||||
std::thread m_thread;
|
||||
int m_line;
|
||||
|
||||
public:
|
||||
|
||||
void setLeftImage(SvImage& image) { m_left = ℑ}
|
||||
void setRightImage(SvImage& image) { m_right = ℑ}
|
||||
bool isActive() { return m_thread.joinable(); }
|
||||
void join() { m_thread.join(); }
|
||||
void detach() { m_thread.detach(); }
|
||||
|
||||
int run(SvImage& stereo, int line);
|
||||
void process();
|
||||
virtual void exec();
|
||||
|
||||
SvMultithreadProcessor(SvImage& left, SvImage& right);
|
||||
SvMultithreadProcessor();
|
||||
|
||||
virtual ~SvMultithreadProcessor();
|
||||
};
|
||||
|
||||
#endif /* SVMULTITHREADPROCESSOR_H_ */
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* SvProcessor.cpp
|
||||
*
|
||||
* Created on: 27 июня 2014 г.
|
||||
* Author: andrey
|
||||
*/
|
||||
|
||||
#include "SvProcessorV1.h"
|
||||
|
||||
int SvProcessorV1::getPixelColor(int cursor) {
|
||||
if (cursor == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ((10 * m_left->getWidth()) / (2.0 * 0.9 * cursor ));
|
||||
}
|
||||
/*
|
||||
int SvProcessorV1::match(int x, int y, int j) {
|
||||
int error = 0;
|
||||
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
for (int g = 0; g <= 2; g++) {
|
||||
error += diff(x + i, y + g, x + i + j, y + g);
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}*/
|
||||
|
||||
int SvProcessorV1::diff(int lx, int ly, int rx, int ry) {
|
||||
int Rvalue, Gvalue, Bvalue, color;
|
||||
|
||||
Rvalue = abs(m_left->getPixel(lx, ly, 0) - m_right->getPixel(rx, ry, 0));
|
||||
Gvalue = abs(m_left->getPixel(lx, ly, 1) - m_right->getPixel(rx, ry, 1));
|
||||
Bvalue = abs(m_left->getPixel(lx, ly, 2) - m_right->getPixel(rx, ry, 2));
|
||||
color = abs(Gvalue - Rvalue) + abs(Bvalue - Gvalue);
|
||||
|
||||
return (Gvalue + Rvalue + Bvalue) +
|
||||
color * 4;
|
||||
}
|
||||
|
||||
int SvProcessorV1::match(int x, int y, int j) {
|
||||
int error = 0;
|
||||
int ms = 4;
|
||||
int c = diff(x, y, x + j, y),
|
||||
l = 0, r = 0, t = 0, b = 0;
|
||||
|
||||
error = c;
|
||||
|
||||
for (int i = 1; i <= ms; i++) {
|
||||
l += diff(x - i, y, x + j - i, y);
|
||||
r += diff(x + i, y, x + j + i, y);
|
||||
t += diff(x, y - i, x + j, y - i);
|
||||
b += diff(x, y + i, x + j, y + i);
|
||||
}
|
||||
|
||||
error += l > r ? r : l;
|
||||
error += t > b ? b : t;
|
||||
//error += l + r + b + t;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void SvProcessorV1::exec() {
|
||||
int x, y, cursor, closest, tmp;
|
||||
int minErrorValue, tmpSmoothed, matched;
|
||||
int precursor, preprecursor;
|
||||
int dist, diff, val, prev, preprev;
|
||||
|
||||
cursor = 0;
|
||||
precursor = 0;
|
||||
preprecursor = 0;
|
||||
|
||||
for (x = 0; x < m_stereo->getWidth(); x++) {
|
||||
closest = -1; minErrorValue = -1;matched=0;
|
||||
minErrorValue=-1;
|
||||
|
||||
val = m_left->getPixelHue(x, m_line);
|
||||
|
||||
for (int i = 1; i < windowSize; i++) {
|
||||
dist = (abs(cursor - i));
|
||||
|
||||
tmp = match(x, m_line, i);
|
||||
|
||||
tmpSmoothed = tmp;// + (dist) * (1.0/diff);
|
||||
|
||||
if (tmpSmoothed < minErrorValue || minErrorValue == -1) {
|
||||
minErrorValue = tmpSmoothed;
|
||||
closest = i;
|
||||
matched = 1;
|
||||
} else if (tmpSmoothed == minErrorValue) {
|
||||
if (abs(cursor - i) < abs(cursor - closest)) {
|
||||
closest = i;
|
||||
matched++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (matched == 1) {
|
||||
cursor = closest;
|
||||
}
|
||||
|
||||
m_stereo->putPixel(x, m_line, getPixelColor(cursor));
|
||||
|
||||
preprecursor = precursor;
|
||||
precursor = cursor;
|
||||
|
||||
preprev = prev;
|
||||
prev = val;
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
/*
|
||||
* SvProcessor.h
|
||||
*
|
||||
* Created on: 27 июня 2014 г.
|
||||
* Author: andrey
|
||||
*/
|
||||
|
||||
#ifndef SVPROCESSORV1_H_
|
||||
#define SVPROCESSORV1_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include "SvImage.h"
|
||||
#include "SvMultithreadProcessor.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SvProcessorV1 : public SvMultithreadProcessor {
|
||||
|
||||
protected:
|
||||
const int windowSize = 90;
|
||||
|
||||
public:
|
||||
int diff(int lx, int ly, int rx, int ry);
|
||||
int match(int x, int y, int i);
|
||||
void exec();
|
||||
|
||||
int getPixelColor(int cursor);
|
||||
};
|
||||
|
||||
#endif /* SVPROCESSORV1_H_ */
|
@ -1,12 +0,0 @@
|
||||
/*
|
||||
* SvProcessor.cpp
|
||||
*
|
||||
* Created on: 27 июня 2014 г.
|
||||
* Author: andrey
|
||||
*/
|
||||
|
||||
#include "SvProcessorV2.h"
|
||||
|
||||
void SvProcessorV2::exec() {
|
||||
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* SvProcessor.h
|
||||
*
|
||||
* Created on: 27 июня 2014 г.
|
||||
* Author: andrey
|
||||
*/
|
||||
|
||||
#ifndef SVPROCESSOR_H_
|
||||
#define SVPROCESSOR_H_
|
||||
|
||||
#include <iostream>
|
||||
#include "SvImage.h"
|
||||
#include "SvMultithreadProcessor.h"
|
||||
|
||||
class SvProcessorV2 : public SvMultithreadProcessor {
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
void exec();
|
||||
};
|
||||
|
||||
#endif /* SVPROCESSOR_H_ */
|
22
svabstractkernel.h
Normal file
22
svabstractkernel.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef SVABSTRACTKERNEL_H
|
||||
#define SVABSTRACTKERNEL_H
|
||||
|
||||
#include "svimage.h"
|
||||
|
||||
class SvAbstractKernel
|
||||
{
|
||||
|
||||
protected:
|
||||
SvImage* m_left;
|
||||
SvImage* m_right;
|
||||
SvImage* m_result;
|
||||
|
||||
public:
|
||||
void setLeftImage(SvImage* image) {m_left = image;}
|
||||
void setRightImage(SvImage* image) {m_right = image;}
|
||||
void setResultImage(SvImage* image) {m_result = image;}
|
||||
virtual void exec(int line) = 0;
|
||||
virtual ~SvAbstractKernel() {}
|
||||
};
|
||||
|
||||
#endif // SVABSTRACTKERNEL_H
|
5
svcurve.cpp
Normal file
5
svcurve.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "svcurve.h"
|
||||
|
||||
SvCurve::SvCurve()
|
||||
{
|
||||
}
|
19
svcurve.h
Normal file
19
svcurve.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef SVCURVE_H
|
||||
#define SVCURVE_H
|
||||
|
||||
#include "svpoint.h"
|
||||
|
||||
class SvPoint;
|
||||
|
||||
class SvCurve
|
||||
{
|
||||
protected:
|
||||
SvPoint *m_ends;
|
||||
SvPoint *m_points;
|
||||
SvSimplePoint *m_keyPoints;
|
||||
|
||||
public:
|
||||
SvCurve();
|
||||
};
|
||||
|
||||
#endif // SVCURVE_H
|
5
svfigure.cpp
Normal file
5
svfigure.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "svfigure.h"
|
||||
|
||||
SvFigure::SvFigure()
|
||||
{
|
||||
}
|
17
svfigure.h
Normal file
17
svfigure.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef SVFIGURE_H
|
||||
#define SVFIGURE_H
|
||||
|
||||
#include "svpoint.h"
|
||||
#include "svcurve.h"
|
||||
|
||||
class SvFigure
|
||||
{
|
||||
protected:
|
||||
SvPoint ends[2];
|
||||
|
||||
|
||||
public:
|
||||
SvFigure();
|
||||
};
|
||||
|
||||
#endif // SVFIGURE_H
|
148
svimage.cpp
Normal file
148
svimage.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
#include "svimage.h"
|
||||
|
||||
int SvImage::getPixel(int x, int y, int channel) {
|
||||
if (y >= m_image->height() ||
|
||||
y < 0 ||
|
||||
x >= m_image->width()
|
||||
|| x < 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRgb rgb = m_image->pixel(x, y);
|
||||
|
||||
switch (channel) {
|
||||
case 0:
|
||||
return qRed(rgb);
|
||||
case 1:
|
||||
return qGreen(rgb);
|
||||
case 2:
|
||||
return qBlue(rgb);
|
||||
default:
|
||||
return qGray(rgb);
|
||||
}
|
||||
}
|
||||
|
||||
int SvImage::getPixelNormalizedHue(int x, int y) {
|
||||
if (y >= m_image->height() ||
|
||||
y < 0 ||
|
||||
x >= m_image->width()
|
||||
|| x < 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRgb rgb = m_image->pixel(x, y);
|
||||
QColor color(rgb);
|
||||
|
||||
return (color.hsvHue() * getPixelSaturation(x, y)) / 255;
|
||||
}
|
||||
|
||||
int SvImage::getPixelHue(int x, int y) {
|
||||
if (y >= m_image->height() ||
|
||||
y < 0 ||
|
||||
x >= m_image->width()
|
||||
|| x < 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRgb rgb = m_image->pixel(x, y);
|
||||
QColor color(rgb);
|
||||
|
||||
return color.hsvHue();
|
||||
}
|
||||
|
||||
int SvImage::getPixelValue(int x, int y) {
|
||||
if (y >= m_image->height() ||
|
||||
y < 0 ||
|
||||
x >= m_image->width()
|
||||
|| x < 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRgb rgb = m_image->pixel(x, y);
|
||||
QColor color(rgb);
|
||||
|
||||
return color.value();
|
||||
}
|
||||
|
||||
int SvImage::getPixelSaturation(int x, int y)
|
||||
{
|
||||
if (y >= m_image->height() ||
|
||||
y < 0 ||
|
||||
x >= m_image->width()
|
||||
|| x < 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
QRgb rgb = m_image->pixel(x, y);
|
||||
QColor color(rgb);
|
||||
|
||||
return color.saturation();
|
||||
}
|
||||
|
||||
QRgb SvImage::getPixelRGB(int x, int y)
|
||||
{
|
||||
if (y >= m_image->height() ||
|
||||
y < 0 ||
|
||||
x >= m_image->width()
|
||||
|| x < 0) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_image->pixel(x, y);
|
||||
}
|
||||
|
||||
void SvImage::putGrayPixel(int x, int y, int value)
|
||||
{
|
||||
if (y >= m_image->height() ||
|
||||
y < 0 ||
|
||||
x >= m_image->width()
|
||||
|| x < 0) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (value > 255) {
|
||||
value = 255;
|
||||
}
|
||||
|
||||
m_image->setPixel(x, y, qRgb(value, value, value));
|
||||
}
|
||||
|
||||
void SvImage::putPixel(int x, int y, int red, int green, int blue)
|
||||
{
|
||||
if (y >= m_image->height() ||
|
||||
y < 0 ||
|
||||
x >= m_image->width()
|
||||
|| x < 0) {
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
m_image->setPixel(x, y, qRgb(red, green, blue));
|
||||
}
|
||||
|
||||
unsigned int SvImage::getHeight() {
|
||||
return m_image->height();
|
||||
}
|
||||
|
||||
unsigned int SvImage::getWidth() {
|
||||
return m_image->width();
|
||||
}
|
||||
|
||||
QImage& SvImage::getImage() {
|
||||
return *m_image;
|
||||
}
|
||||
|
||||
SvImage::SvImage(QImage& image) {
|
||||
m_image = ℑ
|
||||
}
|
||||
|
||||
SvImage::~SvImage() {
|
||||
|
||||
}
|
32
svimage.h
Normal file
32
svimage.h
Normal file
@ -0,0 +1,32 @@
|
||||
#ifndef SVIMAGE_H
|
||||
#define SVIMAGE_H
|
||||
|
||||
#include <QImage>
|
||||
#include <QRgb>
|
||||
#include <QColor>
|
||||
|
||||
class SvImage
|
||||
{
|
||||
protected:
|
||||
QImage* m_image;
|
||||
|
||||
public:
|
||||
int getPixel(int x, int y, int channel = -1);
|
||||
int getPixelHue(int x, int y);
|
||||
int getPixelNormalizedHue(int x, int y);
|
||||
int getPixelValue(int x, int y);
|
||||
int getPixelSaturation(int x, int y);
|
||||
QRgb getPixelRGB(int x, int y);
|
||||
void putGrayPixel(int x, int y, int val);
|
||||
void putPixel(int x, int y, int red, int green, int blue);
|
||||
|
||||
unsigned int getHeight();
|
||||
unsigned int getWidth();
|
||||
|
||||
QImage& getImage();
|
||||
|
||||
SvImage(QImage& image);
|
||||
virtual ~SvImage();
|
||||
};
|
||||
|
||||
#endif // SVIMAGE_H
|
27
svimageprovider.cpp
Normal file
27
svimageprovider.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include "svimageprovider.h"
|
||||
|
||||
SvImageProvider::SvImageProvider():
|
||||
QQuickImageProvider(QQuickImageProvider::Image)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QImage SvImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
|
||||
{
|
||||
Q_UNUSED(requestedSize)
|
||||
|
||||
SvImage* image = m_images[id];
|
||||
|
||||
if (image) {
|
||||
*size = QSize(image->getWidth(), image->getHeight());
|
||||
|
||||
return image->getImage();
|
||||
}
|
||||
|
||||
return QImage(0, 0, QImage::Format_RGB32);
|
||||
}
|
||||
|
||||
void SvImageProvider::addImage(const QString &name, SvImage *image)
|
||||
{
|
||||
m_images[name] = image;
|
||||
}
|
22
svimageprovider.h
Normal file
22
svimageprovider.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef SVIMAGEPROVIDER_H
|
||||
#define SVIMAGEPROVIDER_H
|
||||
|
||||
#include <QtQuick/QQuickImageProvider>
|
||||
#include <QHash>
|
||||
|
||||
#include "svimage.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
class SvImageProvider : public QQuickImageProvider
|
||||
{
|
||||
protected:
|
||||
QHash<QString, SvImage*> m_images;
|
||||
|
||||
public:
|
||||
SvImageProvider();
|
||||
virtual QImage requestImage(const QString &id, QSize *size, const QSize& requestedSize);
|
||||
void addImage(const QString &name, SvImage* image);
|
||||
};
|
||||
|
||||
#endif // SVIMAGEPROVIDER_H
|
105
svkernelv1.cpp
Normal file
105
svkernelv1.cpp
Normal file
@ -0,0 +1,105 @@
|
||||
#include "svkernelv1.h"
|
||||
|
||||
SvKernelV1::SvKernelV1()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SvKernelV1::~SvKernelV1()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
int SvKernelV1::getPixelColor(int cursor)
|
||||
{
|
||||
if (cursor == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ((10 * m_left->getWidth()) / (2.0 * 0.9 * cursor ));
|
||||
}
|
||||
|
||||
int SvKernelV1::diff(int lx, int ly, int rx, int ry)
|
||||
{
|
||||
int Red, Green, Blue, color;
|
||||
|
||||
int Lvalue = m_left->getPixelValue(lx, ly);
|
||||
int Rvalue = m_right->getPixelValue(rx, ry);
|
||||
|
||||
int dLvalue = m_left->getPixelValue(rx - 1, ry) - Lvalue;
|
||||
int dRvalue = m_right->getPixelValue(rx - 1, ry) - Rvalue;
|
||||
|
||||
int dLsign = dLvalue >= 0 ? 1 : -1;
|
||||
int dRsign = dRvalue >= 0 ? 1 : -1;
|
||||
|
||||
Red = abs(m_left->getPixel(lx, ly, 0) - m_right->getPixel(rx, ry, 0));
|
||||
Green = abs(m_left->getPixel(lx, ly, 1) - m_right->getPixel(rx, ry, 1));
|
||||
Blue = abs(m_left->getPixel(lx, ly, 2) - m_right->getPixel(rx, ry, 2));
|
||||
color = abs(Green - Red) + abs(Blue - Green);
|
||||
|
||||
return ((Green + Red + Blue) +
|
||||
color << 2) + (dLsign == dRsign ? 0 : 100);
|
||||
}
|
||||
|
||||
int SvKernelV1::match(int x, int y, int j)
|
||||
{
|
||||
int error = 0;
|
||||
int ms = 5;
|
||||
int c = diff(x, y, x + j, y),
|
||||
l = 0, r = 0, t = 0, b = 0;
|
||||
|
||||
error = c;
|
||||
|
||||
for (int i = 1; i <= ms; i++) {
|
||||
l += diff(x - i, y, x + j - i, y);
|
||||
r += diff(x + i, y, x + j + i, y);
|
||||
t += diff(x, y - i, x + j, y - i);
|
||||
b += diff(x, y + i, x + j, y + i);
|
||||
}
|
||||
|
||||
error += l > r ? r : l;
|
||||
error += t > b ? b : t;
|
||||
//error += l + r + b + t;
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void SvKernelV1::exec(int line)
|
||||
{
|
||||
unsigned int x;
|
||||
int cursor, closest, tmp;
|
||||
int minErrorValue, tmpSmoothed, matched;
|
||||
int dist;
|
||||
|
||||
cursor = 0;
|
||||
|
||||
for (x = 0; x < m_result->getWidth(); x+=1) {
|
||||
closest = -1; minErrorValue = -1;matched=0;
|
||||
minErrorValue=-1;
|
||||
|
||||
for (int i = 1; i < m_windowSize; i++) {
|
||||
dist = (abs(cursor - i));
|
||||
|
||||
tmp = match(x, line, i);
|
||||
tmpSmoothed = tmp;
|
||||
|
||||
if (tmpSmoothed < minErrorValue || minErrorValue == -1) {
|
||||
minErrorValue = tmpSmoothed;
|
||||
closest = i;
|
||||
matched = 1;
|
||||
} else if (tmpSmoothed == minErrorValue) {
|
||||
if (abs(cursor - i) < abs(cursor - closest)) {
|
||||
closest = i;
|
||||
matched++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (matched == 1) {
|
||||
cursor = closest;
|
||||
}
|
||||
|
||||
m_result->putGrayPixel(x/* + cursor*/, line, getPixelColor(cursor));
|
||||
}
|
||||
}
|
23
svkernelv1.h
Normal file
23
svkernelv1.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef SVKERNELV1_H
|
||||
#define SVKERNELV1_H
|
||||
|
||||
#include "svabstractkernel.h"
|
||||
|
||||
class SvKernelV1: public SvAbstractKernel
|
||||
{
|
||||
|
||||
protected:
|
||||
int m_windowSize = 160;
|
||||
|
||||
public:
|
||||
void exec(int line) override;
|
||||
SvKernelV1();
|
||||
virtual ~SvKernelV1();
|
||||
|
||||
protected:
|
||||
int getPixelColor(int cursor);
|
||||
int diff(int lx, int ly, int rx, int ry);
|
||||
int match(int x, int y, int i);
|
||||
};
|
||||
|
||||
#endif // SVKERNELV1_H
|
99
svkernelv2.cpp
Normal file
99
svkernelv2.cpp
Normal file
@ -0,0 +1,99 @@
|
||||
#include "svkernelv2.h"
|
||||
|
||||
SvKernelV2::SvKernelV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SvKernelV2::~SvKernelV2()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int SvKernelV2::rgbDiff(QRgb left, QRgb right)
|
||||
{
|
||||
QColor cLeft(left);
|
||||
QColor cRight(right);
|
||||
|
||||
int leftDiff = max(qBlue(left), qRed(left), qGreen(left)) -
|
||||
min(qBlue(left), qRed(left), qGreen(left));
|
||||
|
||||
int rightDiff = max(qBlue(right), qRed(right), qGreen(right)) -
|
||||
min(qBlue(right), qRed(right), qGreen(right));
|
||||
|
||||
int minDiff= leftDiff < rightDiff ? rightDiff : leftDiff;
|
||||
|
||||
int diff = cLeft.value() - cRight.value();
|
||||
int hsvDiff = minDiff > 70 ? abs(cLeft.hsvHue() - cRight.hsvHue()) : 0;
|
||||
if (hsvDiff > 180) {
|
||||
hsvDiff = 360 - hsvDiff;
|
||||
}
|
||||
|
||||
int dsign = sign(diff);
|
||||
dsign = dsign == 0 ? 1 : dsign;
|
||||
|
||||
return /*dsign * ((rightDiff - leftDiff)>>2) + */diff /*+ (hsvDiff > 5 ? dsign * 10 : 0)*/;
|
||||
}
|
||||
|
||||
void SvKernelV2::exec(int line)
|
||||
{
|
||||
QRgb vtop, top, right, bottom, vbottom, _xy, xy;
|
||||
|
||||
int __dX, _dX, dX, dX_,
|
||||
__dY, _dY, dY, dY_;
|
||||
|
||||
int value;
|
||||
|
||||
for (int x = 0; x < m_result->getWidth(); x++) {
|
||||
value = 0;
|
||||
|
||||
vtop = m_left->getPixelRGB(x - 1, line - 3);
|
||||
top = m_left->getPixelRGB(x - 1, line - 2);
|
||||
right = m_left->getPixelRGB(x, line - 1);
|
||||
bottom = m_left->getPixelRGB(x - 1, line);
|
||||
vbottom = m_left->getPixelRGB(x - 1, line + 1);
|
||||
xy = m_left->getPixelRGB(x - 1, line - 1);
|
||||
|
||||
dX_ = rgbDiff(_xy, right);
|
||||
dY_ = rgbDiff(vtop, top);
|
||||
dY = rgbDiff(top, _xy);
|
||||
_dY = rgbDiff(_xy, bottom);
|
||||
__dY = rgbDiff(bottom, vbottom);
|
||||
|
||||
if ( dX >= _dX && dX > dX_ ||
|
||||
dX <= _dX && dX < dX_) {
|
||||
if (dX == _dX) {
|
||||
if (dX > dX_ && _dX > __dX ||
|
||||
dX < dX_ && _dX < __dX) {
|
||||
value += abs(dX);
|
||||
}
|
||||
} else {
|
||||
value += abs(dX);
|
||||
}
|
||||
}
|
||||
|
||||
if ( dY >= _dY && dY > dY_ ||
|
||||
dY <= _dY && dY < dY_) {
|
||||
|
||||
if (dY == _dY) {
|
||||
if (dY > dY_ && _dY > __dY ||
|
||||
dY < dY_ && _dY < __dY) {
|
||||
|
||||
value += abs(dY);
|
||||
}
|
||||
} else {
|
||||
value += abs(dY);
|
||||
}
|
||||
}
|
||||
|
||||
if (value > 0) {
|
||||
m_result->putGrayPixel(x - 1, line - 1, value);
|
||||
}
|
||||
|
||||
__dX = _dX;
|
||||
_dX = dX;
|
||||
dX = dX_;
|
||||
_xy = right;
|
||||
}
|
||||
}
|
||||
|
19
svkernelv2.h
Normal file
19
svkernelv2.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef SVKERNELV2_H
|
||||
#define SVKERNELV2_H
|
||||
|
||||
#include "svabstractkernel.h"
|
||||
#include <QDebug>
|
||||
#define sign(a) (a == 0 ? 0 : (a > 0 ? 1 : -1))
|
||||
#define max(a,b,c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
|
||||
#define min(a,b,c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
|
||||
|
||||
class SvKernelV2: public SvAbstractKernel
|
||||
{
|
||||
public:
|
||||
SvKernelV2();
|
||||
virtual ~SvKernelV2();
|
||||
void exec(int line) override;
|
||||
int rgbDiff(QRgb left, QRgb right);
|
||||
};
|
||||
|
||||
#endif // SVKERNELV2_H
|
5
svobject.cpp
Normal file
5
svobject.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "svobject.h"
|
||||
|
||||
SvObject::SvObject()
|
||||
{
|
||||
}
|
15
svobject.h
Normal file
15
svobject.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef SVOBJECT_H
|
||||
#define SVOBJECT_H
|
||||
|
||||
#include "svfigure.h"
|
||||
|
||||
class SvObject
|
||||
{
|
||||
protected:
|
||||
SvFigure *m_figures;
|
||||
|
||||
public:
|
||||
SvObject();
|
||||
};
|
||||
|
||||
#endif // SVOBJECT_H
|
5
svpoint.cpp
Normal file
5
svpoint.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "svpoint.h"
|
||||
|
||||
SvPoint::SvPoint()
|
||||
{
|
||||
}
|
34
svpoint.h
Normal file
34
svpoint.h
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef SVPOINT_H
|
||||
#define SVPOINT_H
|
||||
|
||||
#include "svsimplepoint.h"
|
||||
#include "svcurve.h"
|
||||
|
||||
class SvCurve;
|
||||
|
||||
class SvPoint: public SvSimplePoint
|
||||
{
|
||||
public:
|
||||
enum Sides {
|
||||
TOP,
|
||||
BOTTOM,
|
||||
RIGHT,
|
||||
LEFT
|
||||
};
|
||||
|
||||
enum FlowType {
|
||||
HORIZONTAL,
|
||||
VERTICAL,
|
||||
SLASH,
|
||||
BACK_SLASH
|
||||
};
|
||||
|
||||
protected:
|
||||
SvCurve* m_curves;
|
||||
FlowType m_type;
|
||||
|
||||
public:
|
||||
SvPoint();
|
||||
};
|
||||
|
||||
#endif // SVPOINT_H
|
71
svprocessor.cpp
Normal file
71
svprocessor.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
#include "svprocessor.h"
|
||||
|
||||
SvProcessor::SvProcessor(QObject *parent):
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SvProcessor::SvProcessor(SvImage* left, SvImage* right, SvImage* result, int numberOfWorkers, int version)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if (version == 1) {
|
||||
m_kernel = new SvKernelV1();
|
||||
} else if (version == 2) {
|
||||
m_kernel = new SvKernelV2();
|
||||
}
|
||||
|
||||
m_kernel->setLeftImage(left);
|
||||
m_kernel->setRightImage(right);
|
||||
m_kernel->setResultImage(result);
|
||||
|
||||
m_numberOfWorkers = numberOfWorkers;
|
||||
m_workers = new SvWorker[m_numberOfWorkers];
|
||||
m_threads = new QThread[m_numberOfWorkers];
|
||||
|
||||
for (i = 0; i < m_numberOfWorkers; i++) {
|
||||
m_workers[i].setId(i);
|
||||
m_workers[i].setKernel(m_kernel);
|
||||
m_workers[i].moveToThread(&m_threads[i]);
|
||||
|
||||
connect(&m_threads[i], &QThread::started, &m_workers[i], &SvWorker::start);
|
||||
connect(&m_workers[i], &SvWorker::finished, this, &SvProcessor::workerFinished);
|
||||
}
|
||||
|
||||
for (i = 0; i < result->getHeight(); i++) {
|
||||
m_workers[i % m_numberOfWorkers].addTask(i);
|
||||
}
|
||||
}
|
||||
SvProcessor::~SvProcessor()
|
||||
{
|
||||
delete m_kernel;
|
||||
delete[] m_workers;
|
||||
}
|
||||
|
||||
void SvProcessor::workerFinished(int workerId)
|
||||
{
|
||||
qDebug() << "worker " << workerId << " finished";
|
||||
m_workersFinished++;
|
||||
if (m_workersFinished == m_numberOfWorkers) {
|
||||
qDebug() << "finished";
|
||||
emit finished(time(NULL) - m_startTime);
|
||||
}
|
||||
}
|
||||
|
||||
void SvProcessor::start()
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
m_startTime = time(NULL);
|
||||
m_workersFinished = 0;
|
||||
|
||||
for (i = 0; i < m_numberOfWorkers; i++) {
|
||||
m_threads[i].start(QThread::HighestPriority);
|
||||
}
|
||||
}
|
||||
|
||||
void SvProcessor::stop()
|
||||
{
|
||||
emit stopped(time(NULL) - m_startTime);
|
||||
}
|
47
svprocessor.h
Normal file
47
svprocessor.h
Normal file
@ -0,0 +1,47 @@
|
||||
#ifndef SVPROCESSOR_H
|
||||
#define SVPROCESSOR_H
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include<QObject>
|
||||
#include<QThread>
|
||||
#include<QDebug>
|
||||
|
||||
#include "svimage.h"
|
||||
#include "svworker.h"
|
||||
#include "svabstractkernel.h"
|
||||
#include "svkernelv1.h"
|
||||
#include "svkernelv2.h"
|
||||
|
||||
class SvProcessor: public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
QThread* m_threads;
|
||||
SvWorker* m_workers;
|
||||
SvAbstractKernel* m_kernel;
|
||||
unsigned int m_numberOfWorkers;
|
||||
unsigned int m_workersFinished;
|
||||
unsigned int m_startTime;
|
||||
|
||||
public:
|
||||
explicit SvProcessor(QObject *parent = 0);
|
||||
SvProcessor(SvImage *left, SvImage *right, SvImage *result, int numberOfWorkers = 1, int version = 1);
|
||||
~SvProcessor();
|
||||
void execute();
|
||||
|
||||
protected slots:
|
||||
void workerFinished(int workerId);
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
signals:
|
||||
void started();
|
||||
void finished(int elapsedTime);
|
||||
void stopped(int elapsedTime);
|
||||
};
|
||||
|
||||
#endif // SVPROCESSOR_H
|
5
svsimplepoint.cpp
Normal file
5
svsimplepoint.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "svsimplepoint.h"
|
||||
|
||||
SvSimplePoint::SvSimplePoint()
|
||||
{
|
||||
}
|
23
svsimplepoint.h
Normal file
23
svsimplepoint.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef SVSIMPLEPOINT_H
|
||||
#define SVSIMPLEPOINT_H
|
||||
|
||||
class SvSimplePoint
|
||||
{
|
||||
protected:
|
||||
int m_px, m_py, m_pz;
|
||||
|
||||
public:
|
||||
int x() {return m_px;}
|
||||
int y() {return m_py;}
|
||||
int z() {return m_pz;}
|
||||
|
||||
int setX(int px) {return m_px = px;}
|
||||
int setY(int py) {return m_py = py;}
|
||||
int setZ(int pz) {return m_pz = pz;}
|
||||
|
||||
|
||||
|
||||
SvSimplePoint();
|
||||
};
|
||||
|
||||
#endif // SVSIMPLEPOINT_H
|
26
svworker.cpp
Normal file
26
svworker.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "svworker.h"
|
||||
|
||||
SvWorker::SvWorker(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SvWorker::SvWorker(SvAbstractKernel* kernel)
|
||||
{
|
||||
m_kernel = kernel;
|
||||
}
|
||||
|
||||
void SvWorker::stop()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SvWorker::start()
|
||||
{
|
||||
for (int i: m_tasks) {
|
||||
m_kernel->exec(i);
|
||||
}
|
||||
|
||||
emit finished(m_id);
|
||||
}
|
36
svworker.h
Normal file
36
svworker.h
Normal file
@ -0,0 +1,36 @@
|
||||
#ifndef SVWORKER_H
|
||||
#define SVWORKER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QList>
|
||||
|
||||
#include "svabstractkernel.h"
|
||||
#include "svimage.h"
|
||||
|
||||
class SvWorker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
protected:
|
||||
int m_id;
|
||||
SvAbstractKernel* m_kernel;
|
||||
QList<unsigned int> m_tasks;
|
||||
|
||||
public:
|
||||
explicit SvWorker(QObject *parent = 0);
|
||||
SvWorker(SvAbstractKernel* kernel);
|
||||
|
||||
void setId(int id) {m_id = id;}
|
||||
void addTask(int line) {m_tasks << line;}
|
||||
void setKernel(SvAbstractKernel* kernel) {m_kernel = kernel;}
|
||||
|
||||
signals:
|
||||
void finished(int id);
|
||||
|
||||
public slots:
|
||||
void stop();
|
||||
void start();
|
||||
|
||||
};
|
||||
|
||||
#endif // SVWORKER_H
|
Loading…
Reference in New Issue
Block a user