diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da24bf8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/target +.undodir + diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..6095709 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,331 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "adler32" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" + +[[package]] +name = "autocfg" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bytemuck" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72957246c41db82b8ef88a5486143830adeb8227ef9837740bdec67724cf2c5b" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "color_quant" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" + +[[package]] +name = "crc32fast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3825b1e8580894917dc4468cb634a1b4e9745fddc854edad72d9c04644c0319f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "lazy_static", + "memoffset", + "scopeguard", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db" +dependencies = [ + "cfg-if", + "lazy_static", +] + +[[package]] +name = "deflate" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" +dependencies = [ + "adler32", + "byteorder", +] + +[[package]] +name = "dispmap" +version = "0.1.0" +dependencies = [ + "image", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "gif" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3a7187e78088aead22ceedeee99779455b23fc231fe13ec443f99bb71694e5b" +dependencies = [ + "color_quant", + "weezl", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "image" +version = "0.23.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" +dependencies = [ + "bytemuck", + "byteorder", + "color_quant", + "gif", + "jpeg-decoder", + "num-iter", + "num-rational", + "num-traits", + "png", + "scoped_threadpool", + "tiff", +] + +[[package]] +name = "jpeg-decoder" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" +dependencies = [ + "rayon", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" + +[[package]] +name = "memoffset" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +dependencies = [ + "autocfg", +] + +[[package]] +name = "miniz_oxide" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" +dependencies = [ + "adler32", +] + +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + +[[package]] +name = "num-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2021c8337a54d21aca0d59a92577a029af9431cb59b909b03252b9c164fad59" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "png" +version = "0.16.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" +dependencies = [ + "bitflags", + "crc32fast", + "deflate", + "miniz_oxide 0.3.7", +] + +[[package]] +name = "rayon" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90" +dependencies = [ + "autocfg", + "crossbeam-deque", + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "lazy_static", + "num_cpus", +] + +[[package]] +name = "scoped_threadpool" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "tiff" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" +dependencies = [ + "jpeg-decoder", + "miniz_oxide 0.4.4", + "weezl", +] + +[[package]] +name = "weezl" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e7336e7 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "dispmap" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[[bin]] +name = "run" +path = "./bin/run.rs" + + +[dependencies] +image = "0.23.14" diff --git a/README.md b/README.md new file mode 100644 index 0000000..2ba17fe --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Simple Disparity Map Algorithm + + diff --git a/Release/makefile b/Release/makefile deleted file mode 100644 index 0a3be5d..0000000 --- a/Release/makefile +++ /dev/null @@ -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 diff --git a/Release/objects.mk b/Release/objects.mk deleted file mode 100644 index ce28c03..0000000 --- a/Release/objects.mk +++ /dev/null @@ -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 - diff --git a/Release/sources.mk b/Release/sources.mk deleted file mode 100644 index e7f4bf1..0000000 --- a/Release/sources.mk +++ /dev/null @@ -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 \ - diff --git a/Release/src/subdir.mk b/Release/src/subdir.mk deleted file mode 100644 index afc74e1..0000000 --- a/Release/src/subdir.mk +++ /dev/null @@ -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 ' ' - - diff --git a/bin/run.rs b/bin/run.rs new file mode 100644 index 0000000..d12e6f4 --- /dev/null +++ b/bin/run.rs @@ -0,0 +1,6 @@ + + + +fn main() { + +} diff --git a/src/SvImage.cpp b/src/SvImage.cpp deleted file mode 100644 index 5f01ef6..0000000 --- a/src/SvImage.cpp +++ /dev/null @@ -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() { - -} - diff --git a/src/SvImage.h b/src/SvImage.h deleted file mode 100644 index 1166f0b..0000000 --- a/src/SvImage.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * SvImage.h - * - * Created on: 27 июня 2014 г. - * Author: andrey - */ - -#ifndef SVIMAGE_H_ -#define SVIMAGE_H_ - -#include - -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_ */ diff --git a/src/SvMain.cpp b/src/SvMain.cpp deleted file mode 100644 index 0f07b0b..0000000 --- a/src/SvMain.cpp +++ /dev/null @@ -1,102 +0,0 @@ -//============================================================================ -// Name : CSV.cpp -// Author : Andrey -// Version : -// Copyright : Your copyright notice -// Description : Computer Stereo Vision in C++, Ansi-style -//============================================================================ - -#include -#include "SvImage.h" -#include "SvProcessorV1.h" -#include "SvProcessorV2.h" -#include -//#include -//#include -//#include -//#include -//#include -//#include - -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::Ptr cloud(new pcl::PointCloud); - //pcl::PointCloud::Ptr cloud_filtered (new pcl::PointCloud); - - /*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 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; -} diff --git a/src/SvMultithreadProcessor.cpp b/src/SvMultithreadProcessor.cpp deleted file mode 100644 index 5c73e69..0000000 --- a/src/SvMultithreadProcessor.cpp +++ /dev/null @@ -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() { - -} - diff --git a/src/SvMultithreadProcessor.h b/src/SvMultithreadProcessor.h deleted file mode 100644 index 6295f98..0000000 --- a/src/SvMultithreadProcessor.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * SvMultithreadProcessor.h - * - * Created on: 09 июля 2014 г. - * Author: andrey - */ - -#ifndef SVMULTITHREADPROCESSOR_H_ -#define SVMULTITHREADPROCESSOR_H_ - -#include -#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_ */ diff --git a/src/SvProcessorV1.cpp b/src/SvProcessorV1.cpp deleted file mode 100644 index 572c32e..0000000 --- a/src/SvProcessorV1.cpp +++ /dev/null @@ -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; - } -} - diff --git a/src/SvProcessorV1.h b/src/SvProcessorV1.h deleted file mode 100644 index b045389..0000000 --- a/src/SvProcessorV1.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * SvProcessor.h - * - * Created on: 27 июня 2014 г. - * Author: andrey - */ - -#ifndef SVPROCESSORV1_H_ -#define SVPROCESSORV1_H_ - -#include -#include -#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_ */ diff --git a/src/SvProcessorV2.cpp b/src/SvProcessorV2.cpp deleted file mode 100644 index cc9c0f0..0000000 --- a/src/SvProcessorV2.cpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * SvProcessor.cpp - * - * Created on: 27 июня 2014 г. - * Author: andrey - */ - -#include "SvProcessorV2.h" - -void SvProcessorV2::exec() { - -} diff --git a/src/SvProcessorV2.h b/src/SvProcessorV2.h deleted file mode 100644 index b92fd5c..0000000 --- a/src/SvProcessorV2.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SvProcessor.h - * - * Created on: 27 июня 2014 г. - * Author: andrey - */ - -#ifndef SVPROCESSOR_H_ -#define SVPROCESSOR_H_ - -#include -#include "SvImage.h" -#include "SvMultithreadProcessor.h" - -class SvProcessorV2 : public SvMultithreadProcessor { - -protected: - -public: - void exec(); -}; - -#endif /* SVPROCESSOR_H_ */ diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..a842e22 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,106 @@ +use image::{GrayImage, RgbImage}; + +fn diff(left_image: &RgbImage, right_image: &RgbImage, lx: u32, ly: u32, rx: u32, ry: u32) -> i32 { + let r = (left_image.get_pixel(lx, ly)[0] as i8 - right_image.get_pixel(rx, ry)[0] as i8).abs() + as i32; + let g = (left_image.get_pixel(lx, ly)[1] as i8 - right_image.get_pixel(rx, ry)[1] as i8).abs() + as i32; + let b = (left_image.get_pixel(lx, ly)[2] as i8 - right_image.get_pixel(rx, ry)[2] as i8).abs() + as i32; + let color = (g - r).abs() + (b - g).abs(); + + (r + g + b) + color * 4 +} + +fn match_pixels(left_image: &RgbImage, right_image: &RgbImage, x: u32, y: u32, j: u32) -> i32 { + let mut error = 0; + let ms = 4; + let c = diff(left_image, right_image, x, y, x + j, y); + let mut l = 0; + let mut r = 0; + let mut t = 0; + let mut b = 0; + + error = c; + + for i in 1..=ms { + l += diff(left_image, right_image, x - i, y, x + j - i, y); + r += diff(left_image, right_image, x + i, y, x + j + i, y); + t += diff(left_image, right_image, x, y - i, x + j, y - i); + b += diff(left_image, right_image, x, y + i, x + j, y + i); + } + + error += if l > r { r } else { l }; + error += if t > b { b } else { t }; + //error += l + r + b + t; + + error +} + +fn get_pixel_color(image: &RgbImage, cursor: i32) -> f32 { + if cursor == 0 { + return 0.0; + } + + (10 * image.width()) as f32 / (2.0 * 0.9 * cursor as f32) +} + +fn get_pixel_hue(image: &RgbImage, x: u32, y: u32) -> i32 { + let pixel = image.get_pixel(x, y); + + (pixel[1] as i32 - pixel[0] as i32).abs() + (pixel[2] as i32 - pixel[1] as i32).abs() +} + +fn get_pixel_value(image: &RgbImage, x: u32, y: u32) -> i32 { + let pixel = image.get_pixel(x, y); + + (pixel[0] as i32 + pixel[1] as i32 + pixel[2] as i32) / 3 +} + +fn exec(res: &mut GrayImage, left: &RgbImage, right: &RgbImage, line: u32) { + let mut prev = 0; + let mut preprev = 0; + let mut cursor = 0i32; + let mut precursor = 0i32; + let mut preprecursor = 0i32; + + let window_size = 128u32; + + for x in 0..res.width() { + let mut closest = -1i32; + let mut min_error = -1i32; + let mut matched = 0; + + let val = get_pixel_hue(left, x, line); + + for i in 1..window_size { + let dist = (cursor - i as i32).abs(); + let tmp = match_pixels(left, right, x, line, i); + let tmp_smoothed = tmp; // + (dist) * (1.0 / diff); + + if tmp_smoothed < min_error || min_error == -1 { + min_error = tmp_smoothed; + closest = i as i32; + matched = 1; + } else if tmp_smoothed == min_error + && ((cursor - i as i32).abs() < (cursor - closest).abs()) + { + closest = i as i32; + matched += 1; + } + } + + if matched == 1 { + cursor = closest; + } + + res.put_pixel(x, line, ([get_pixel_color(left, cursor) as u8]).into()); + + preprecursor = precursor; + precursor = cursor; + + preprev = prev; + prev = val; + } +} +