From 9908ff33dec00402a3793b87ce4c4087080141b6 Mon Sep 17 00:00:00 2001 From: Ivan Korolev Date: Wed, 30 Jan 2013 11:04:15 +0400 Subject: [PATCH 01/16] Added regression test for HoughLines algorithm --- modules/imgproc/test/test_houghLines.cpp | 149 +++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 modules/imgproc/test/test_houghLines.cpp diff --git a/modules/imgproc/test/test_houghLines.cpp b/modules/imgproc/test/test_houghLines.cpp new file mode 100644 index 0000000000..9f2d27fc90 --- /dev/null +++ b/modules/imgproc/test/test_houghLines.cpp @@ -0,0 +1,149 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "test_precomp.hpp" + +using namespace cv; +using namespace std; + +class CV_HoughLinesTest : public cvtest::BaseTest +{ +public: + enum {STANDART = 0, PROBABILISTIC}; + CV_HoughLinesTest() {} + ~CV_HoughLinesTest() {} +protected: + void run_test(int type); +}; + +class CV_StandartHoughLinesTest : public CV_HoughLinesTest +{ +public: + CV_StandartHoughLinesTest() {} + ~CV_StandartHoughLinesTest() {} + virtual void run(int); +}; + +class CV_ProbabilisticHoughLinesTest : public CV_HoughLinesTest +{ +public: + CV_ProbabilisticHoughLinesTest() {} + ~CV_ProbabilisticHoughLinesTest() {} + virtual void run(int); +}; + +void CV_StandartHoughLinesTest::run(int) +{ + run_test(STANDART); +} + +void CV_ProbabilisticHoughLinesTest::run(int) +{ + run_test(PROBABILISTIC); +} + +void CV_HoughLinesTest::run_test(int type) +{ + Mat src = imread(string(ts->get_data_path()) + "shared/pic1.png"); + if (src.empty()) + { + ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + return; + } + + string xml; + if (type == STANDART) + xml = string(ts->get_data_path()) + "imgproc/HoughLines.xml"; + else if (type == PROBABILISTIC) + xml = string(ts->get_data_path()) + "imgproc/HoughLinesP.xml"; + else + { + ts->printf(cvtest::TS::LOG, "Error: unknown HoughLines algorithm type.\n"); + ts->set_failed_test_info(cvtest::TS::FAIL_GENERIC); + return; + } + + Mat dst; + Canny(src, dst, 50, 200, 3); + + Mat lines; + if (type == STANDART) + HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0); + else if (type == PROBABILISTIC) + HoughLinesP(dst, lines, 1, CV_PI/180, 100, 0, 0); + + FileStorage fs(xml, FileStorage::READ); + if (!fs.isOpened()) + { + fs.open(xml, FileStorage::WRITE); + if (!fs.isOpened()) + { + ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + return; + } + fs << "exp_lines" << lines; + fs.release(); + fs.open(xml, FileStorage::READ); + if (!fs.isOpened()) + { + ts->set_failed_test_info(cvtest::TS::FAIL_INVALID_TEST_DATA); + return; + } + } + + Mat exp_lines; + read( fs["exp_lines"], exp_lines, Mat() ); + fs.release(); + + if ( exp_lines.size != lines.size || norm(exp_lines, lines, NORM_INF) > 1e-4 ) + { + ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH); + return; + } + + ts->set_failed_test_info(cvtest::TS::OK); +} + +TEST(Imgproc_HoughLines, regression) { CV_StandartHoughLinesTest test; test.safe_run(); } + +TEST(Imgproc_HoughLinesP, regression) { CV_ProbabilisticHoughLinesTest test; test.safe_run(); } + From 56fbcc541f4e8fb8248bbf0973cc1c6e7da423d9 Mon Sep 17 00:00:00 2001 From: Ilya Lysenkov Date: Wed, 30 Jan 2013 15:25:10 +0400 Subject: [PATCH 02/16] Tested cvDestroyAllWindows() without windows --- modules/highgui/test/test_gui.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/highgui/test/test_gui.cpp b/modules/highgui/test/test_gui.cpp index 8704f68e1f..285203cb04 100644 --- a/modules/highgui/test/test_gui.cpp +++ b/modules/highgui/test/test_gui.cpp @@ -58,6 +58,9 @@ void Foo(int /*k*/, void* /*z*/) {} void CV_HighGuiOnlyGuiTest::run( int /*start_from */) { + ts->printf(ts->LOG, "GUI 0\n"); + cvDestroyAllWindows(); + ts->printf(ts->LOG, "GUI 1\n"); namedWindow("Win"); From 3c8787980c53da2afeafd1a7c09ff853aedb6b33 Mon Sep 17 00:00:00 2001 From: Ilya Lysenkov Date: Wed, 30 Jan 2013 15:26:49 +0400 Subject: [PATCH 03/16] Fixed cvDestroyAllWindows() without windows in QT (#2440) --- modules/highgui/src/window_QT.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/window_QT.cpp b/modules/highgui/src/window_QT.cpp index d617e71f9f..973b23c0c0 100644 --- a/modules/highgui/src/window_QT.cpp +++ b/modules/highgui/src/window_QT.cpp @@ -499,7 +499,7 @@ CV_IMPL void cvDestroyWindow(const char* name) CV_IMPL void cvDestroyAllWindows() { if (!guiMainThread) - CV_Error( CV_StsNullPtr, "NULL guiReceiver (please create a window)" ); + return; QMetaObject::invokeMethod(guiMainThread, "destroyAllWindow", From b362affd1360882a5ca16fea3b2069d3d4c5adbf Mon Sep 17 00:00:00 2001 From: Ivan Korolev Date: Wed, 30 Jan 2013 13:10:50 +0400 Subject: [PATCH 04/16] Fixed bug in the cv::estimateRigidTransform (#1949) --- modules/video/src/lkpyramid.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index bad5558622..d05c5fd9cc 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -1911,8 +1911,11 @@ cv::Mat cv::estimateRigidTransform( InputArray src1, { Mat M(2, 3, CV_64F), A = src1.getMat(), B = src2.getMat(); CvMat matA = A, matB = B, matM = M; - cvEstimateRigidTransform(&matA, &matB, &matM, fullAffine); - return M; + int err = cvEstimateRigidTransform(&matA, &matB, &matM, fullAffine); + if (err == 1) + return M; + else + return Mat(); } /* End of file. */ From 6a29b13c457986090dd68592d549354fac0d282a Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 30 Jan 2013 16:07:38 +0400 Subject: [PATCH 05/16] Add test for issue #2075 --- modules/video/test/test_optflowpyrlk.cpp | 32 +++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/video/test/test_optflowpyrlk.cpp b/modules/video/test/test_optflowpyrlk.cpp index f44e213a86..9a9035b98d 100644 --- a/modules/video/test/test_optflowpyrlk.cpp +++ b/modules/video/test/test_optflowpyrlk.cpp @@ -211,4 +211,34 @@ _exit_: TEST(Video_OpticalFlowPyrLK, accuracy) { CV_OptFlowPyrLKTest test; test.safe_run(); } -/* End of file. */ +TEST(Video_OpticalFlowPyrLK, submat) +{ + // see bug #2075 + std::string path = cvtest::TS::ptr()->get_data_path() + "../cv/shared/lena.png"; + + cv::Mat lenaImg = cv::imread(path); + ASSERT_FALSE(lenaImg.empty()); + + cv::Mat wholeImage; + cv::resize(lenaImg, wholeImage, cv::Size(1024, 1024)); + + cv::Mat img1 = wholeImage(cv::Rect(0, 0, 640, 360)).clone(); + cv::Mat img2 = wholeImage(cv::Rect(40, 60, 640, 360)); + + std::vector status; + std::vector error; + std::vector prev; + std::vector next; + + cv::RNG rng(123123); + + for(int i = 0; i < 50; ++i) + { + int x = rng.uniform(0, 640); + int y = rng.uniform(0, 360); + + prev.push_back(cv::Point2f((float)x, (float)y)); + } + + ASSERT_NO_THROW(cv::calcOpticalFlowPyrLK(img1, img2, prev, next, status, error)); +} From c9d8e9900fc9d9daabccabdb39a79ca0b9413354 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 30 Jan 2013 16:07:55 +0400 Subject: [PATCH 06/16] Allow input of calcOpticalFlowPyrLK be submats of different size images This fixes bug #2075 --- modules/video/src/lkpyramid.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/video/src/lkpyramid.cpp b/modules/video/src/lkpyramid.cpp index bad5558622..9344a72b19 100644 --- a/modules/video/src/lkpyramid.cpp +++ b/modules/video/src/lkpyramid.cpp @@ -213,8 +213,8 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const int iw11 = (1 << W_BITS) - iw00 - iw01 - iw10; int dstep = (int)(derivI.step/derivI.elemSize1()); - int step = (int)(I.step/I.elemSize1()); - CV_Assert( step == (int)(J.step/J.elemSize1()) ); + int stepI = (int)(I.step/I.elemSize1()); + int stepJ = (int)(J.step/J.elemSize1()); float A11 = 0, A12 = 0, A22 = 0; #if CV_SSE2 @@ -230,7 +230,7 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const int x, y; for( y = 0; y < winSize.height; y++ ) { - const uchar* src = (const uchar*)I.data + (y + iprevPt.y)*step + iprevPt.x*cn; + const uchar* src = (const uchar*)I.data + (y + iprevPt.y)*stepI + iprevPt.x*cn; const deriv_type* dsrc = (const deriv_type*)derivI.data + (y + iprevPt.y)*dstep + iprevPt.x*cn2; deriv_type* Iptr = (deriv_type*)(IWinBuf.data + y*IWinBuf.step); @@ -245,8 +245,8 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const v00 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int*)(src + x)), z); v01 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int*)(src + x + cn)), z); - v10 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int*)(src + x + step)), z); - v11 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int*)(src + x + step + cn)), z); + v10 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int*)(src + x + stepI)), z); + v11 = _mm_unpacklo_epi8(_mm_cvtsi32_si128(*(const int*)(src + x + stepI + cn)), z); t0 = _mm_add_epi32(_mm_madd_epi16(_mm_unpacklo_epi16(v00, v01), qw0), _mm_madd_epi16(_mm_unpacklo_epi16(v10, v11), qw1)); @@ -282,7 +282,7 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const for( ; x < winSize.width*cn; x++, dsrc += 2, dIptr += 2 ) { int ival = CV_DESCALE(src[x]*iw00 + src[x+cn]*iw01 + - src[x+step]*iw10 + src[x+step+cn]*iw11, W_BITS1-5); + src[x+stepI]*iw10 + src[x+stepI+cn]*iw11, W_BITS1-5); int ixval = CV_DESCALE(dsrc[0]*iw00 + dsrc[cn2]*iw01 + dsrc[dstep]*iw10 + dsrc[dstep+cn2]*iw11, W_BITS1); int iyval = CV_DESCALE(dsrc[1]*iw00 + dsrc[cn2+1]*iw01 + dsrc[dstep+1]*iw10 + @@ -359,7 +359,7 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const for( y = 0; y < winSize.height; y++ ) { - const uchar* Jptr = (const uchar*)J.data + (y + inextPt.y)*step + inextPt.x*cn; + const uchar* Jptr = (const uchar*)J.data + (y + inextPt.y)*stepJ + inextPt.x*cn; const deriv_type* Iptr = (const deriv_type*)(IWinBuf.data + y*IWinBuf.step); const deriv_type* dIptr = (const deriv_type*)(derivIWinBuf.data + y*derivIWinBuf.step); @@ -371,8 +371,8 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const __m128i diff0 = _mm_loadu_si128((const __m128i*)(Iptr + x)), diff1; __m128i v00 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x)), z); __m128i v01 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x + cn)), z); - __m128i v10 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x + step)), z); - __m128i v11 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x + step + cn)), z); + __m128i v10 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x + stepJ)), z); + __m128i v11 = _mm_unpacklo_epi8(_mm_loadl_epi64((const __m128i*)(Jptr + x + stepJ + cn)), z); __m128i t0 = _mm_add_epi32(_mm_madd_epi16(_mm_unpacklo_epi16(v00, v01), qw0), _mm_madd_epi16(_mm_unpacklo_epi16(v10, v11), qw1)); @@ -403,7 +403,7 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const for( ; x < winSize.width*cn; x++, dIptr += 2 ) { int diff = CV_DESCALE(Jptr[x]*iw00 + Jptr[x+cn]*iw01 + - Jptr[x+step]*iw10 + Jptr[x+step+cn]*iw11, + Jptr[x+stepJ]*iw10 + Jptr[x+stepJ+cn]*iw11, W_BITS1-5) - Iptr[x]; b1 += (float)(diff*dIptr[0]); b2 += (float)(diff*dIptr[1]); @@ -465,13 +465,13 @@ void cv::detail::LKTrackerInvoker::operator()(const BlockedRange& range) const for( y = 0; y < winSize.height; y++ ) { - const uchar* Jptr = (const uchar*)J.data + (y + inextPoint.y)*step + inextPoint.x*cn; + const uchar* Jptr = (const uchar*)J.data + (y + inextPoint.y)*stepJ + inextPoint.x*cn; const deriv_type* Iptr = (const deriv_type*)(IWinBuf.data + y*IWinBuf.step); for( x = 0; x < winSize.width*cn; x++ ) { int diff = CV_DESCALE(Jptr[x]*iw00 + Jptr[x+cn]*iw01 + - Jptr[x+step]*iw10 + Jptr[x+step+cn]*iw11, + Jptr[x+stepJ]*iw10 + Jptr[x+stepJ+cn]*iw11, W_BITS1-5) - Iptr[x]; errval += std::abs((float)diff); } From 11871528cee96fc7133bfc3093903f4689abb0cc Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 30 Jan 2013 16:36:50 +0400 Subject: [PATCH 07/16] Solve conflict between tiff.h and opencv2/core/types_c.h MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Сonflict exists between some versions of libtiff and opencv headers --- modules/highgui/test/test_grfmt.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/highgui/test/test_grfmt.cpp b/modules/highgui/test/test_grfmt.cpp index 28d30c9b07..c408d89a4d 100644 --- a/modules/highgui/test/test_grfmt.cpp +++ b/modules/highgui/test/test_grfmt.cpp @@ -294,7 +294,12 @@ TEST(Highgui_Jpeg, encode_empty) #ifdef HAVE_TIFF + +// these defines are used to resolve conflict between tiff.h and opencv2/core/types_c.h +#define uint64 uint64_hack_ +#define int64 int64_hack_ #include "tiff.h" + TEST(Highgui_Tiff, decode_tile16384x16384) { // see issue #2161 From eaa50121636aeb382832fc67d12b8155b9a47963 Mon Sep 17 00:00:00 2001 From: Ivan Korolev Date: Wed, 30 Jan 2013 17:04:33 +0400 Subject: [PATCH 08/16] fix v4l yes-yes build --- modules/highgui/src/cap_v4l.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/highgui/src/cap_v4l.cpp b/modules/highgui/src/cap_v4l.cpp index fdbd120faa..829d0ab638 100644 --- a/modules/highgui/src/cap_v4l.cpp +++ b/modules/highgui/src/cap_v4l.cpp @@ -214,7 +214,7 @@ make & enjoy! #include #include -#ifdef HAVE_CAMVAL +#ifdef HAVE_CAMV4L #include #endif From 26c7e7f2924ac733923033c86f9282160f601d3e Mon Sep 17 00:00:00 2001 From: Ivan Korolev Date: Wed, 30 Jan 2013 17:17:04 +0400 Subject: [PATCH 09/16] fix default include dirs for TBB --- cmake/OpenCVDetectTBB.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/OpenCVDetectTBB.cmake b/cmake/OpenCVDetectTBB.cmake index 1ffd45475c..94f5b89e95 100644 --- a/cmake/OpenCVDetectTBB.cmake +++ b/cmake/OpenCVDetectTBB.cmake @@ -22,7 +22,7 @@ endif() if(NOT HAVE_TBB) set(TBB_DEFAULT_INCLUDE_DIRS - "/opt/intel/tbb" "/usr/local/include" "/usr/include" + "/opt/intel/tbb/include" "/usr/local/include" "/usr/include" "C:/Program Files/Intel/TBB" "C:/Program Files (x86)/Intel/TBB" "C:/Program Files (x86)/tbb/include" "C:/Program Files (x86)/tbb/include" From f489eb9a5d853d7cbd667ffaace73b015a5a47a3 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Wed, 30 Jan 2013 17:25:03 +0400 Subject: [PATCH 10/16] Fix build warnings in OpenCL samples --- .../include/opencv2/ocl/matrix_operations.hpp | 28 +++++++++---------- samples/ocl/facedetect.cpp | 2 +- samples/ocl/squares.cpp | 8 +++--- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/modules/ocl/include/opencv2/ocl/matrix_operations.hpp b/modules/ocl/include/opencv2/ocl/matrix_operations.hpp index d528aeb020..4b617ce07c 100644 --- a/modules/ocl/include/opencv2/ocl/matrix_operations.hpp +++ b/modules/ocl/include/opencv2/ocl/matrix_operations.hpp @@ -141,7 +141,7 @@ namespace cv } - inline oclMat::oclMat(const oclMat &m, const Range &rowRange, const Range &colRange) + inline oclMat::oclMat(const oclMat &m, const Range &rRange, const Range &cRange) { flags = m.flags; step = m.step; @@ -152,22 +152,22 @@ namespace cv wholerows = m.wholerows; wholecols = m.wholecols; offset = m.offset; - if( rowRange == Range::all() ) + if( rRange == Range::all() ) rows = m.rows; else { - CV_Assert( 0 <= rowRange.start && rowRange.start <= rowRange.end && rowRange.end <= m.rows ); - rows = rowRange.size(); - offset += step * rowRange.start; + CV_Assert( 0 <= rRange.start && rRange.start <= rRange.end && rRange.end <= m.rows ); + rows = rRange.size(); + offset += step * rRange.start; } - if( colRange == Range::all() ) + if( cRange == Range::all() ) cols = m.cols; else { - CV_Assert( 0 <= colRange.start && colRange.start <= colRange.end && colRange.end <= m.cols ); - cols = colRange.size(); - offset += colRange.start * elemSize(); + CV_Assert( 0 <= cRange.start && cRange.start <= cRange.end && cRange.end <= m.cols ); + cols = cRange.size(); + offset += cRange.start * elemSize(); flags &= cols < m.cols ? ~Mat::CONTINUOUS_FLAG : -1; } @@ -296,12 +296,12 @@ namespace cv //CPP void oclMat::copyTo( oclMat& m, const oclMat& mask ) const; //CPP void oclMat::convertTo( oclMat& m, int rtype, double alpha=1, double beta=0 ) const; - inline void oclMat::assignTo( oclMat &m, int type ) const + inline void oclMat::assignTo( oclMat &m, int mtype ) const { - if( type < 0 ) + if( mtype < 0 ) m = *this; else - convertTo(m, type); + convertTo(m, mtype); } //CPP oclMat& oclMat::operator = (const Scalar& s); @@ -370,9 +370,9 @@ namespace cv return *this; } - inline oclMat oclMat::operator()( Range rowRange, Range colRange ) const + inline oclMat oclMat::operator()( Range rRange, Range cRange ) const { - return oclMat(*this, rowRange, colRange); + return oclMat(*this, rRange, cRange); } inline oclMat oclMat::operator()( const Rect &roi ) const { diff --git a/samples/ocl/facedetect.cpp b/samples/ocl/facedetect.cpp index 16017b9284..ec79339518 100644 --- a/samples/ocl/facedetect.cpp +++ b/samples/ocl/facedetect.cpp @@ -10,7 +10,7 @@ using namespace std; using namespace cv; -void help() +static void help() { cout << "\nThis program demonstrates the cascade recognizer.\n" "This classifier can recognize many ~rigid objects, it's most known use is for faces.\n" diff --git a/samples/ocl/squares.cpp b/samples/ocl/squares.cpp index f70945342b..6b184161f7 100644 --- a/samples/ocl/squares.cpp +++ b/samples/ocl/squares.cpp @@ -14,7 +14,7 @@ using namespace cv; using namespace std; -void help() +static void help() { cout << "\nA program using OCL module pyramid scaling, Canny, dilate functions, threshold, split; cpu contours, contour simpification and\n" @@ -34,7 +34,7 @@ const char* wndname = "OpenCL Square Detection Demo"; // helper function: // finds a cosine of angle between vectors // from pt0->pt1 and from pt0->pt2 -double angle( Point pt1, Point pt2, Point pt0 ) +static double angle( Point pt1, Point pt2, Point pt0 ) { double dx1 = pt1.x - pt0.x; double dy1 = pt1.y - pt0.y; @@ -45,7 +45,7 @@ double angle( Point pt1, Point pt2, Point pt0 ) // returns sequence of squares detected on the image. // the sequence is stored in the specified memory storage -void findSquares( const Mat& image, vector >& squares ) +static void findSquares( const Mat& image, vector >& squares ) { squares.clear(); @@ -131,7 +131,7 @@ void findSquares( const Mat& image, vector >& squares ) // the function draws all the squares in the image -void drawSquares( Mat& image, const vector >& squares ) +static void drawSquares( Mat& image, const vector >& squares ) { for( size_t i = 0; i < squares.size(); i++ ) { From 5bc6365ba52a48726dcf535d75246a93044d3bf6 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 30 Jan 2013 17:28:22 +0400 Subject: [PATCH 11/16] TestCheckVector java test fixed. Warning fixed. --- .../java/android_test/src/org/opencv/test/OpenCVTestCase.java | 2 -- .../java/android_test/src/org/opencv/test/core/MatTest.java | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java index 59fcc27672..5c932110d3 100644 --- a/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java +++ b/modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java @@ -2,11 +2,9 @@ package org.opencv.test; import java.io.BufferedReader; import java.io.File; -import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; -import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.charset.Charset; import java.util.List; diff --git a/modules/java/android_test/src/org/opencv/test/core/MatTest.java b/modules/java/android_test/src/org/opencv/test/core/MatTest.java index e270e40158..a2570f4342 100644 --- a/modules/java/android_test/src/org/opencv/test/core/MatTest.java +++ b/modules/java/android_test/src/org/opencv/test/core/MatTest.java @@ -62,7 +62,7 @@ public class MatTest extends OpenCVTestCase { assertEquals(2, new Mat(2, 10, CvType.CV_8U).checkVector(10)); assertEquals(2, new Mat(1, 2, CvType.CV_8UC(10)).checkVector(10)); assertEquals(2, new Mat(2, 1, CvType.CV_8UC(10)).checkVector(10)); - assertEquals(2, new Mat(1, 10, CvType.CV_8UC2).checkVector(10)); + assertEquals(10, new Mat(1, 10, CvType.CV_8UC2).checkVector(2)); assertTrue(0 > new Mat().checkVector(0)); assertTrue(0 > new Mat(10, 1, CvType.CV_8U).checkVector(10)); @@ -73,7 +73,7 @@ public class MatTest extends OpenCVTestCase { assertEquals(2, new Mat(2, 10, CvType.CV_8U).checkVector(10, CvType.CV_8U)); assertEquals(2, new Mat(1, 2, CvType.CV_8UC(10)).checkVector(10, CvType.CV_8U)); assertEquals(2, new Mat(2, 1, CvType.CV_8UC(10)).checkVector(10, CvType.CV_8U)); - assertEquals(2, new Mat(1, 10, CvType.CV_8UC2).checkVector(10, CvType.CV_8U)); + assertEquals(10, new Mat(1, 10, CvType.CV_8UC2).checkVector(2, CvType.CV_8U)); assertTrue(0 > new Mat(2, 10, CvType.CV_8U).checkVector(10, CvType.CV_8S)); assertTrue(0 > new Mat(1, 2, CvType.CV_8UC(10)).checkVector(10, CvType.CV_8S)); From 1f261c2f9db912b48be0a3486bcdd1f8ca76eb2f Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Wed, 30 Jan 2013 18:07:37 +0400 Subject: [PATCH 12/16] changed default parameters of SURF, which improved its performance. Restored bi-linear interpolation in SURF descriptor extractor. Added test for SURF homography + check for non-zero (positive) responses. --- modules/nonfree/src/surf.cpp | 37 +++++++++++++++++-- modules/nonfree/test/test_features2d.cpp | 6 ++- .../test_rotation_and_scale_invariance.cpp | 2 +- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/modules/nonfree/src/surf.cpp b/modules/nonfree/src/surf.cpp index 9a4cd28a69..bb6d53e4b9 100644 --- a/modules/nonfree/src/surf.cpp +++ b/modules/nonfree/src/surf.cpp @@ -698,11 +698,12 @@ struct SURFInvoker cvGetQuadrangleSubPix( img, &win, &W ); */ - // Nearest neighbour version (faster) float win_offset = -(float)(win_size-1)/2; float start_x = center.x + win_offset*cos_dir + win_offset*sin_dir; float start_y = center.y - win_offset*sin_dir + win_offset*cos_dir; uchar* WIN = win.data; +#if 0 + // Nearest neighbour version (faster) for( i = 0; i < win_size; i++, start_x += sin_dir, start_y += cos_dir ) { float pixel_x = start_x; @@ -714,6 +715,36 @@ struct SURFInvoker WIN[i*win_size + j] = img->at(y, x); } } +#else + int ncols1 = img->cols-1, nrows1 = img->rows-1; + size_t imgstep = img->step; + for( i = 0; i < win_size; i++, start_x += sin_dir, start_y += cos_dir ) + { + double pixel_x = start_x; + double pixel_y = start_y; + for( j = 0; j < win_size; j++, pixel_x += cos_dir, pixel_y -= sin_dir ) + { + int ix = cvFloor(pixel_x), iy = cvFloor(pixel_y); + if( (unsigned)ix < (unsigned)ncols1 && + (unsigned)iy < (unsigned)nrows1 ) + { + float a = (float)(pixel_x - ix), b = (float)(pixel_y - iy); + const uchar* imgptr = &img->at(iy, ix); + WIN[i*win_size + j] = (uchar) + cvRound(imgptr[0]*(1.f - a)*(1.f - b) + + imgptr[1]*a*(1.f - b) + + imgptr[imgstep]*(1.f - a)*b + + imgptr[imgstep+1]*a*b); + } + else + { + int x = std::min(std::max(cvRound(pixel_x), 0), ncols1); + int y = std::min(std::max(cvRound(pixel_y), 0), nrows1); + WIN[i*win_size + j] = img->at(y, x); + } + } + } +#endif } else { @@ -844,10 +875,10 @@ struct SURFInvoker SURF::SURF() { hessianThreshold = 100; - extended = true; + extended = false; upright = false; nOctaves = 4; - nOctaveLayers = 2; + nOctaveLayers = 3; } SURF::SURF(double _threshold, int _nOctaves, int _nOctaveLayers, bool _extended, bool _upright) diff --git a/modules/nonfree/test/test_features2d.cpp b/modules/nonfree/test/test_features2d.cpp index a4cc373b78..001d628aaa 100644 --- a/modules/nonfree/test/test_features2d.cpp +++ b/modules/nonfree/test/test_features2d.cpp @@ -1114,6 +1114,10 @@ protected: Mat d1, d2; f->operator()(img1, Mat(), kpt1, d1); f->operator()(img1, Mat(), kpt2, d2); + for( size_t i = 0; i < kpt1.size(); i++ ) + CV_Assert(kpt1[i].response > 0 ); + for( size_t i = 0; i < kpt2.size(); i++ ) + CV_Assert(kpt2[i].response > 0 ); vector matches; BFMatcher(NORM_L2, true).match(d1, d2, matches); @@ -1140,5 +1144,5 @@ protected: }; TEST(Features2d_SIFTHomographyTest, regression) { CV_DetectPlanarTest test("SIFT", 80); test.safe_run(); } -//TEST(Features2d_SURFHomographyTest, regression) { CV_DetectPlanarTest test("SURF", 80); test.safe_run(); } +TEST(Features2d_SURFHomographyTest, regression) { CV_DetectPlanarTest test("SURF", 80); test.safe_run(); } diff --git a/modules/nonfree/test/test_rotation_and_scale_invariance.cpp b/modules/nonfree/test/test_rotation_and_scale_invariance.cpp index 6262456d9d..e0e731eb0b 100644 --- a/modules/nonfree/test/test_rotation_and_scale_invariance.cpp +++ b/modules/nonfree/test/test_rotation_and_scale_invariance.cpp @@ -616,7 +616,7 @@ protected: TEST(Features2d_RotationInvariance_Detector_SURF, regression) { DetectorRotationInvarianceTest test(Algorithm::create("Feature2D.SURF"), - 0.45f, + 0.44f, 0.76f); test.safe_run(); } From 5b03d47fb8dd5eccd4db8144a997d9dfd04f08e0 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Wed, 30 Jan 2013 19:28:16 +0400 Subject: [PATCH 13/16] fix broken links in cascade classification documentation --- modules/objdetect/doc/cascade_classification.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/objdetect/doc/cascade_classification.rst b/modules/objdetect/doc/cascade_classification.rst index f86a985615..eb07a6c8f7 100644 --- a/modules/objdetect/doc/cascade_classification.rst +++ b/modules/objdetect/doc/cascade_classification.rst @@ -21,15 +21,15 @@ The word "cascade" in the classifier name means that the resultant classifier co The feature used in a particular classifier is specified by its shape (1a, 2b etc.), position within the region of interest and the scale (this scale is not the same as the scale used at the detection stage, though these two scales are multiplied). For example, in the case of the third line feature (2c) the response is calculated as the difference between the sum of image pixels under the rectangle covering the whole feature (including the two white stripes and the black stripe in the middle) and the sum of the image pixels under the black stripe multiplied by 3 in order to compensate for the differences in the size of areas. The sums of pixel values over a rectangular regions are calculated rapidly using integral images (see below and the :ocv:func:`integral` description). To see the object detector at work, have a look at the facedetect demo: -http://code.opencv.org/projects/opencv/repository/revisions/master/entry/samples/cpp/facedetect.cpp +http://code.opencv.org/projects/opencv/repository/revisions/master/entry/samples/cpp/dbt_face_detection.cpp The following reference is for the detection part only. There is a separate application called ``opencv_traincascade`` that can train a cascade of boosted classifiers from a set of samples. .. note:: In the new C++ interface it is also possible to use LBP (local binary pattern) features in addition to Haar-like features. -.. [Viola01] Paul Viola and Michael J. Jones. Rapid Object Detection using a Boosted Cascade of Simple Features. IEEE CVPR, 2001. The paper is available online at http://www.ai.mit.edu/people/viola/ +.. [Viola01] Paul Viola and Michael J. Jones. Rapid Object Detection using a Boosted Cascade of Simple Features. IEEE CVPR, 2001. The paper is available online at http://research.microsoft.com/en-us/um/people/viola/Pubs/Detect/violaJones_CVPR2001.pdf -.. [Lienhart02] Rainer Lienhart and Jochen Maydt. An Extended Set of Haar-like Features for Rapid Object Detection. IEEE ICIP 2002, Vol. 1, pp. 900-903, Sep. 2002. This paper, as well as the extended technical report, can be retrieved at http://www.lienhart.de/Publications/publications.html +.. [Lienhart02] Rainer Lienhart and Jochen Maydt. An Extended Set of Haar-like Features for Rapid Object Detection. IEEE ICIP 2002, Vol. 1, pp. 900-903, Sep. 2002. This paper, as well as the extended technical report, can be retrieved at http://www.multimedia-computing.de/mediawiki//images/5/52/MRL-TR-May02-revised-Dec02.pdf FeatureEvaluator @@ -177,7 +177,7 @@ Loads a classifier from a file. CascadeClassifier::read --------------------------- -Reads a classifier from a FileStorage node. +Reads a classifier from a FileStorage node. .. ocv:function:: bool CascadeClassifier::read(const FileNode& node) From 8b3c717e8f4e5c07e403561a22717fd9905561a0 Mon Sep 17 00:00:00 2001 From: "marina.kolpakova" Date: Wed, 30 Jan 2013 20:20:06 +0400 Subject: [PATCH 14/16] apply patch #2686 --- modules/gpu/include/opencv2/gpu/device/common.hpp | 2 +- modules/gpu/src/cuda/canny.cu | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/gpu/include/opencv2/gpu/device/common.hpp b/modules/gpu/include/opencv2/gpu/device/common.hpp index 7fb1036e84..64d82c83b0 100644 --- a/modules/gpu/include/opencv2/gpu/device/common.hpp +++ b/modules/gpu/include/opencv2/gpu/device/common.hpp @@ -100,7 +100,7 @@ namespace cv { namespace gpu typedef unsigned char uchar; typedef unsigned short ushort; typedef signed char schar; - #ifdef _WIN32 + #if defined (_WIN32) || defined (__APPLE__) typedef unsigned int uint; #endif diff --git a/modules/gpu/src/cuda/canny.cu b/modules/gpu/src/cuda/canny.cu index 0a5daebaaf..1afcddc9c9 100644 --- a/modules/gpu/src/cuda/canny.cu +++ b/modules/gpu/src/cuda/canny.cu @@ -43,6 +43,7 @@ #if !defined CUDA_DISABLER #include +#include //std::swap #include "opencv2/gpu/device/common.hpp" #include "opencv2/gpu/device/emulation.hpp" #include "opencv2/gpu/device/transform.hpp" From 2d6253609cf967f5c24f61ceac7bf06210dab09c Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Thu, 31 Jan 2013 02:12:54 +0400 Subject: [PATCH 15/16] Fix truncation of fourcc value in dshow capture property setter (bug #2535) Added test checking that all valid fourcc values are converted properly --- modules/highgui/src/cap_dshow.cpp | 8 +- modules/highgui/test/test_fourcc.cpp | 115 +++++++++++++++++++++++++++ 2 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 modules/highgui/test/test_fourcc.cpp diff --git a/modules/highgui/src/cap_dshow.cpp b/modules/highgui/src/cap_dshow.cpp index d197b015a5..b1b142c79b 100644 --- a/modules/highgui/src/cap_dshow.cpp +++ b/modules/highgui/src/cap_dshow.cpp @@ -1203,7 +1203,7 @@ bool videoInput::setupDevice(int deviceNumber, int w, int h){ bool videoInput::setupDeviceFourcc(int deviceNumber, int w, int h,int fourcc){ if(deviceNumber >= VI_MAX_CAMERAS || VDList[deviceNumber]->readyToCapture) return false; - if ( fourcc > 0 ) { + if ( fourcc != -1 ) { GUID *mediaType = getMediaSubtypeFromFourcc(fourcc); if ( mediaType ) { setAttemptCaptureSize(deviceNumber,w,h,*mediaType); @@ -2193,7 +2193,7 @@ int videoInput::getFourccFromMediaSubtype(GUID type) { GUID *videoInput::getMediaSubtypeFromFourcc(int fourcc){ for (int i=0;i Date: Wed, 30 Jan 2013 21:39:26 +0400 Subject: [PATCH 16/16] Fix and test for #2607 --- modules/objdetect/src/hog.cpp | 2 +- modules/objdetect/test/test_cascadeandhog.cpp | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/objdetect/src/hog.cpp b/modules/objdetect/src/hog.cpp index 9388c5b2ee..f1a32c4340 100644 --- a/modules/objdetect/src/hog.cpp +++ b/modules/objdetect/src/hog.cpp @@ -138,7 +138,7 @@ void HOGDescriptor::write(FileStorage& fs, const String& objName) const << "gammaCorrection" << gammaCorrection << "nlevels" << nlevels; if( !svmDetector.empty() ) - fs << "SVMDetector" << "[:" << svmDetector << "]"; + fs << "SVMDetector" << svmDetector; fs << "}"; } diff --git a/modules/objdetect/test/test_cascadeandhog.cpp b/modules/objdetect/test/test_cascadeandhog.cpp index e41314a8e2..3f31a7ec5d 100644 --- a/modules/objdetect/test/test_cascadeandhog.cpp +++ b/modules/objdetect/test/test_cascadeandhog.cpp @@ -461,5 +461,30 @@ int CV_HOGDetectorTest::detectMultiScale( int di, const Mat& img, return cvtest::TS::OK; } +//----------------------------------------------- HOGDetectorReadWriteTest ----------------------------------- +TEST(Objdetect_HOGDetectorReadWrite, regression) +{ + // Inspired by bug #2607 + Mat img; + img = imread(cvtest::TS::ptr()->get_data_path() + "/cascadeandhog/images/karen-and-rob.png"); + ASSERT_FALSE(img.empty()); + + HOGDescriptor hog; + hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector()); + + string tempfilename = cv::tempfile(".xml"); + FileStorage fs(tempfilename, FileStorage::WRITE); + hog.write(fs, "myHOG"); + + fs.open(tempfilename, FileStorage::READ); + remove(tempfilename.c_str()); + + FileNode n = fs["opencv_storage"]["myHOG"]; + + ASSERT_NO_THROW(hog.read(n)); +} + + + TEST(Objdetect_CascadeDetector, regression) { CV_CascadeDetectorTest test; test.safe_run(); } TEST(Objdetect_HOGDetector, regression) { CV_HOGDetectorTest test; test.safe_run(); }