diff --git a/modules/structured_light/CMakeLists.txt b/modules/structured_light/CMakeLists.txt index 494d58c8b..66bcc2756 100644 --- a/modules/structured_light/CMakeLists.txt +++ b/modules/structured_light/CMakeLists.txt @@ -1,2 +1,2 @@ set(the_description "Structured Light API") -ocv_define_module(structured_light opencv_core opencv_calib3d opencv_imgproc opencv_highgui opencv_features2d opencv_viz opencv_rgbd) \ No newline at end of file +ocv_define_module(structured_light opencv_core opencv_calib3d opencv_imgproc opencv_highgui opencv_features2d opencv_rgbd OPTIONAL opencv_viz) diff --git a/modules/structured_light/samples/pointcloud.cpp b/modules/structured_light/samples/pointcloud.cpp index f006dcb0f..97419dcc1 100644 --- a/modules/structured_light/samples/pointcloud.cpp +++ b/modules/structured_light/samples/pointcloud.cpp @@ -45,7 +45,12 @@ #include #include #include +#include + +// (if you did not build the opencv_viz module, you will only see the disparity images) +#ifdef HAVE_OPENCV_VIZ #include +#endif using namespace std; using namespace cv; @@ -73,13 +78,13 @@ static bool readStringList( const string& filename, vector& l ) if( !fs.isOpened() ) { cerr << "failed to open " << filename << endl; - return -1; + return false; } FileNode n = fs.getFirstTopLevelNode(); if( n.type() != FileNode::SEQ ) { cerr << "cam 1 images are not a sequence! FAIL" << endl; - return -1; + return false; } FileNodeIterator it = n.begin(), it_end = n.end(); @@ -92,7 +97,7 @@ static bool readStringList( const string& filename, vector& l ) if( n.type() != FileNode::SEQ ) { cerr << "cam 2 images are not a sequence! FAIL" << endl; - return -1; + return false; } it = n.begin(), it_end = n.end(); @@ -104,7 +109,7 @@ static bool readStringList( const string& filename, vector& l ) if( l.size() % 2 != 0 ) { cout << "Error: the image list contains odd (non-even) number of elements\n"; - return -1; + return false; } return true; } @@ -133,8 +138,8 @@ int main( int argc, char** argv ) if( argc == 7 ) { // If passed, setting the white and black threshold, otherwise using default values - white_thresh = parser.get( 4 ); - black_thresh = parser.get( 5 ); + white_thresh = parser.get( 4 ); + black_thresh = parser.get( 5 ); graycode->setWhiteThreshold( white_thresh ); graycode->setBlackThreshold( black_thresh ); @@ -271,6 +276,7 @@ int main( int argc, char** argv ) resize( thresholded_disp, dst, Size( 640, 480 ) ); imshow( "threshold disp otsu", dst ); +#ifdef HAVE_OPENCV_VIZ // Apply the mask to the point cloud Mat pointcloud_tresh, color_tresh; pointcloud.copyTo( pointcloud_tresh, thresholded_disp ); @@ -283,8 +289,10 @@ int main( int argc, char** argv ) myWindow.showWidget( "pointcloud", viz::WCloud( pointcloud_tresh, color_tresh ) ); myWindow.showWidget( "text2d", viz::WText( "Point cloud", Point(20, 20), 20, viz::Color::green() ) ); myWindow.spin(); +#endif // HAVE_OPENCV_VIZ + } waitKey(); return 0; -} \ No newline at end of file +} diff --git a/modules/structured_light/src/graycodepattern.cpp b/modules/structured_light/src/graycodepattern.cpp index 0418c8980..d3df7aa2a 100644 --- a/modules/structured_light/src/graycodepattern.cpp +++ b/modules/structured_light/src/graycodepattern.cpp @@ -89,11 +89,11 @@ class CV_EXPORTS_W GrayCodePattern_Impl : public GrayCodePattern // Number between 0-255 that represents the minimum brightness difference // between the fully illuminated (white) and the non - illuminated images (black) - int blackThreshold; + size_t blackThreshold; // Number between 0-255 that represents the minimum brightness difference // between the gray-code pattern and its inverse images - int whiteThreshold; + size_t whiteThreshold; // Computes the required number of pattern images, allocating the pattern vector void computeNumberOfPatternImages(); @@ -220,8 +220,8 @@ bool GrayCodePattern_Impl::decode( InputArrayOfArrays patternImages, OutputArray std::vector shadowMasks; computeShadowMasks( blackImages, whitheImages, shadowMasks ); - size_t cam_width = acquired_pattern[0][0].cols; - size_t cam_height = acquired_pattern[0][0].rows; + int cam_width = acquired_pattern[0][0].cols; + int cam_height = acquired_pattern[0][0].rows; Point projPixel; @@ -233,9 +233,9 @@ bool GrayCodePattern_Impl::decode( InputArrayOfArrays patternImages, OutputArray for( size_t k = 0; k < acquired_pattern.size(); k++ ) { camsPixels[k].resize( params.height * params.width ); - for( size_t i = 0; i < cam_width; i++ ) + for( int i = 0; i < cam_width; i++ ) { - for( size_t j = 0; j < cam_height; j++ ) + for( int j = 0; j < cam_height; j++ ) { //if the pixel is not shadowed, reconstruct if( shadowMasks[k].at( j, i ) ) @@ -345,10 +345,10 @@ void GrayCodePattern_Impl::computeShadowMasks( InputArrayOfArrays blackImages, I { for( int j = 0; j < cam_height; j++ ) { - uchar white = whiteImages_[k].at( Point( i, j ) ); - uchar black = blackImages_[k].at( Point( i, j ) ); + double white = whiteImages_[k].at( Point( i, j ) ); + double black = blackImages_[k].at( Point( i, j ) ); - if( white - black > blackThreshold ) + if( abs(white - black) > blackThreshold ) { shadowMasks_[k].at( Point( i, j ) ) = ( uchar ) 1; } @@ -472,4 +472,4 @@ Ptr GrayCodePattern::create( const GrayCodePattern::Params& par } } -} \ No newline at end of file +} diff --git a/modules/structured_light/test/test_getProjPixel.cpp b/modules/structured_light/test/test_getProjPixel.cpp index d90955fbc..91c6db5d9 100644 --- a/modules/structured_light/test/test_getProjPixel.cpp +++ b/modules/structured_light/test/test_getProjPixel.cpp @@ -73,12 +73,12 @@ void CV_GetProjPixelTest::run( int ) Point projPixel; - size_t image_width = pattern[0].cols; - size_t image_height = pattern[0].rows; + int image_width = pattern[0].cols; + int image_height = pattern[0].rows; - for( size_t i = 0; i < image_width; i++ ) + for( int i = 0; i < image_width; i++ ) { - for( size_t j = 0; j < image_height; j++ ) + for( int j = 0; j < image_height; j++ ) { //for a (x,y) pixel of the camera returns the corresponding projector pixel bool error = graycode->getProjPixel( pattern, i, j, projPixel ); @@ -97,4 +97,4 @@ TEST( GrayCodePattern, getProjPixel ) { CV_GetProjPixelTest test; test.safe_run(); -} \ No newline at end of file +} diff --git a/modules/structured_light/test/test_plane.cpp b/modules/structured_light/test/test_plane.cpp index 658f24a07..36f5b840c 100644 --- a/modules/structured_light/test/test_plane.cpp +++ b/modules/structured_light/test/test_plane.cpp @@ -45,7 +45,6 @@ #include #include #include -#include using namespace std; using namespace cv; @@ -360,4 +359,4 @@ TEST( GrayCodePattern, plane_reconstruction ) { CV_PlaneTest test; test.safe_run(); -} \ No newline at end of file +}