From c9f51d5eed07dbfe803c12a6b97f86bf662f2b21 Mon Sep 17 00:00:00 2001 From: Firat Kalaycilar Date: Fri, 21 Mar 2014 09:44:11 +0200 Subject: [PATCH 01/30] modified BackgroundSubtractorMOG2::getBackgroundImage so that it can now work with gray-level images. --- modules/video/src/bgfg_gaussmix2.cpp | 53 +++++++++++++--------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/modules/video/src/bgfg_gaussmix2.cpp b/modules/video/src/bgfg_gaussmix2.cpp index b14bc8e1e..ddc8e64bd 100644 --- a/modules/video/src/bgfg_gaussmix2.cpp +++ b/modules/video/src/bgfg_gaussmix2.cpp @@ -577,54 +577,49 @@ void BackgroundSubtractorMOG2::operator()(InputArray _image, OutputArray _fgmask void BackgroundSubtractorMOG2::getBackgroundImage(OutputArray backgroundImage) const { int nchannels = CV_MAT_CN(frameType); - CV_Assert( nchannels == 3 ); - Mat meanBackground(frameSize, CV_8UC3, Scalar::all(0)); - + CV_Assert(nchannels == 1 || nchannels == 3); + Mat meanBackground(frameSize, CV_MAKETYPE(CV_8U, nchannels), Scalar::all(0)); int firstGaussianIdx = 0; const GMM* gmm = (GMM*)bgmodel.data; - const Vec3f* mean = reinterpret_cast(gmm + frameSize.width*frameSize.height*nmixtures); + const float* mean = reinterpret_cast(gmm + frameSize.width*frameSize.height*nmixtures); for(int row=0; row(row, col); - Vec3f meanVal; + std::vector meanVal(nchannels, 0.f); float totalWeight = 0.f; for(int gaussianIdx = firstGaussianIdx; gaussianIdx < firstGaussianIdx + nmodes; gaussianIdx++) { GMM gaussian = gmm[gaussianIdx]; - meanVal += gaussian.weight * mean[gaussianIdx]; + size_t meanPosition = gaussianIdx*nchannels; + for(int chn = 0; chn < nchannels; chn++) + { + meanVal[chn] += gaussian.weight * mean[meanPosition + chn]; + } totalWeight += gaussian.weight; if(totalWeight > backgroundRatio) break; } - - meanVal *= (1.f / totalWeight); - meanBackground.at(row, col) = Vec3b(meanVal); + float invWeight = 1.f/totalWeight; + for(int chn = 0; chn < nchannels; chn++) + { + meanVal[chn] *= invWeight; + } + switch(nchannels) + { + case 1: + meanBackground.at(row, col) = (uchar)meanVal[0]; + break; + case 3: + meanBackground.at(row, col) = Vec3b(*reinterpret_cast(&meanVal[0])); + break; + } firstGaussianIdx += nmixtures; } } - - switch(CV_MAT_CN(frameType)) - { - case 1: - { - vector channels; - split(meanBackground, channels); - channels[0].copyTo(backgroundImage); - break; - } - - case 3: - { - meanBackground.copyTo(backgroundImage); - break; - } - - default: - CV_Error(CV_StsUnsupportedFormat, ""); - } + meanBackground.copyTo(backgroundImage); } } From 990295644e4260656787172f959a676bdc0a1066 Mon Sep 17 00:00:00 2001 From: Firat Kalaycilar Date: Tue, 8 Apr 2014 16:10:32 +0300 Subject: [PATCH 02/30] made a performance improvement. changed the way the mean value for each pixel is assigned in the output image. --- modules/video/src/bgfg_gaussmix2.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/video/src/bgfg_gaussmix2.cpp b/modules/video/src/bgfg_gaussmix2.cpp index ddc8e64bd..9700dfebd 100644 --- a/modules/video/src/bgfg_gaussmix2.cpp +++ b/modules/video/src/bgfg_gaussmix2.cpp @@ -582,12 +582,12 @@ void BackgroundSubtractorMOG2::getBackgroundImage(OutputArray backgroundImage) c int firstGaussianIdx = 0; const GMM* gmm = (GMM*)bgmodel.data; const float* mean = reinterpret_cast(gmm + frameSize.width*frameSize.height*nmixtures); + std::vector meanVal(nchannels, 0.f); for(int row=0; row(row, col); - std::vector meanVal(nchannels, 0.f); float totalWeight = 0.f; for(int gaussianIdx = firstGaussianIdx; gaussianIdx < firstGaussianIdx + nmodes; gaussianIdx++) { @@ -603,17 +603,16 @@ void BackgroundSubtractorMOG2::getBackgroundImage(OutputArray backgroundImage) c break; } float invWeight = 1.f/totalWeight; - for(int chn = 0; chn < nchannels; chn++) - { - meanVal[chn] *= invWeight; - } switch(nchannels) { case 1: - meanBackground.at(row, col) = (uchar)meanVal[0]; + meanBackground.at(row, col) = (uchar)(meanVal[0] * invWeight); + meanVal[0] = 0.f; break; case 3: - meanBackground.at(row, col) = Vec3b(*reinterpret_cast(&meanVal[0])); + Vec3f& meanVec = *reinterpret_cast(&meanVal[0]); + meanBackground.at(row, col) = Vec3b(meanVec * invWeight); + meanVec = 0.f; break; } firstGaussianIdx += nmixtures; From dfdb09386f025a1c4b7c2b070e0f617dfcf41200 Mon Sep 17 00:00:00 2001 From: 1Hyena Date: Thu, 1 May 2014 20:55:49 +0300 Subject: [PATCH 03/30] Autotuned_index now prints all info into logger instead of couting it. --- modules/flann/include/opencv2/flann/autotuned_index.h | 8 ++++++-- modules/flann/include/opencv2/flann/params.h | 6 ++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/modules/flann/include/opencv2/flann/autotuned_index.h b/modules/flann/include/opencv2/flann/autotuned_index.h index 8d531753e..2b9ca91a4 100644 --- a/modules/flann/include/opencv2/flann/autotuned_index.h +++ b/modules/flann/include/opencv2/flann/autotuned_index.h @@ -99,18 +99,22 @@ public: */ virtual void buildIndex() { + std::ostringstream stream; bestParams_ = estimateBuildParams(); + print_params(bestParams_, stream); Logger::info("----------------------------------------------------\n"); Logger::info("Autotuned parameters:\n"); - print_params(bestParams_); + Logger::info("%s", stream.str().c_str()); Logger::info("----------------------------------------------------\n"); bestIndex_ = create_index_by_type(dataset_, bestParams_, distance_); bestIndex_->buildIndex(); speedup_ = estimateSearchParams(bestSearchParams_); + stream.str(std::string()); + print_params(bestSearchParams_, stream); Logger::info("----------------------------------------------------\n"); Logger::info("Search parameters:\n"); - print_params(bestSearchParams_); + Logger::info("%s", stream.str().c_str()); Logger::info("----------------------------------------------------\n"); } diff --git a/modules/flann/include/opencv2/flann/params.h b/modules/flann/include/opencv2/flann/params.h index fc2a90619..9ee5b1c9c 100644 --- a/modules/flann/include/opencv2/flann/params.h +++ b/modules/flann/include/opencv2/flann/params.h @@ -79,17 +79,15 @@ T get_param(const IndexParams& params, std::string name) } } -inline void print_params(const IndexParams& params) +inline void print_params(const IndexParams& params, std::ostringstream& stream) { IndexParams::const_iterator it; - for(it=params.begin(); it!=params.end(); ++it) { - std::cout << it->first << " : " << it->second << std::endl; + stream << it->first << " : " << it->second << std::endl; } } - } From 5efd2056f027fdab3b767eb5c1297d2d8271cbff Mon Sep 17 00:00:00 2001 From: Thierry Hoinville Date: Tue, 6 May 2014 15:33:07 +0200 Subject: [PATCH 04/30] Bugfix #3668 in FilterEngine::apply(), use the ROI properly --- modules/imgproc/src/filter.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index 1d05d3c2c..a55c1b0c6 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -453,8 +453,12 @@ void FilterEngine::apply(const Mat& src, Mat& dst, dstOfs.y + srcRoi.height <= dst.rows ); int y = start(src, srcRoi, isolated); - proceed( src.data + y*src.step, (int)src.step, endY - startY, - dst.data + dstOfs.y*dst.step + dstOfs.x*dst.elemSize(), (int)dst.step ); + proceed( src.data + y*src.step + + srcRoi.x*src.elemSize(),/* Bugfix #3668 use the x-shift of ROI + */ + (int)src.step, endY - startY, + dst.data + dstOfs.y*dst.step + + dstOfs.x*dst.elemSize(), (int)dst.step ); } } From 38db7a78df0ae56786d8102ee8f551eb1ecb21ad Mon Sep 17 00:00:00 2001 From: GregoryMorse Date: Tue, 6 May 2014 04:59:07 +0800 Subject: [PATCH 05/30] WinRT core compatibility fixes Update system.cpp Update system.cpp Update system.cpp Update matching.cpp Update matching.cpp --- modules/core/src/system.cpp | 20 ++++++++------------ modules/objdetect/src/matching.cpp | 4 +++- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/modules/core/src/system.cpp b/modules/core/src/system.cpp index ef45b9b5b..68aff531f 100644 --- a/modules/core/src/system.cpp +++ b/modules/core/src/system.cpp @@ -423,27 +423,23 @@ string format( const char* fmt, ... ) string tempfile( const char* suffix ) { -#ifdef HAVE_WINRT - std::wstring temp_dir = L""; - const wchar_t* opencv_temp_dir = _wgetenv(L"OPENCV_TEMP_PATH"); - if (opencv_temp_dir) - temp_dir = std::wstring(opencv_temp_dir); -#else + string fname; +#ifndef HAVE_WINRT const char *temp_dir = getenv("OPENCV_TEMP_PATH"); #endif - string fname; #if defined WIN32 || defined _WIN32 #ifdef HAVE_WINRT RoInitialize(RO_INIT_MULTITHREADED); - std::wstring temp_dir2; - if (temp_dir.empty()) - temp_dir = GetTempPathWinRT(); + std::wstring temp_dir = L""; + const wchar_t* opencv_temp_dir = GetTempPathWinRT().c_str(); + if (opencv_temp_dir) + temp_dir = std::wstring(opencv_temp_dir); std::wstring temp_file; temp_file = GetTempFileNameWinRT(L"ocv"); if (temp_file.empty()) - return std::string(); + return string(); temp_file = temp_dir + std::wstring(L"\\") + temp_file; DeleteFileW(temp_file.c_str()); @@ -451,7 +447,7 @@ string tempfile( const char* suffix ) char aname[MAX_PATH]; size_t copied = wcstombs(aname, temp_file.c_str(), MAX_PATH); CV_Assert((copied != MAX_PATH) && (copied != (size_t)-1)); - fname = std::string(aname); + fname = string(aname); RoUninitialize(); #else char temp_dir2[MAX_PATH] = { 0 }; diff --git a/modules/objdetect/src/matching.cpp b/modules/objdetect/src/matching.cpp index 382f6312a..484605d05 100644 --- a/modules/objdetect/src/matching.cpp +++ b/modules/objdetect/src/matching.cpp @@ -524,7 +524,9 @@ int addNullableBorder(CvLSVMFeatureMap *map, int bx, int by) float *new_map; sizeX = map->sizeX + 2 * bx; sizeY = map->sizeY + 2 * by; - new_map = (float *)malloc(sizeof(float) * sizeX * sizeY * map->numFeatures); + // fix for Windows Phone 8 ARM compiler + size_t size = sizeof(float) * sizeX * sizeY * map->numFeatures; + new_map = (float *)malloc(size); for (i = 0; i < sizeX * sizeY * map->numFeatures; i++) { new_map[i] = 0.0; From e50ef2dab596935f9ed75389ca4acd2f3dbfc77e Mon Sep 17 00:00:00 2001 From: thoinvil Date: Wed, 7 May 2014 18:27:08 +0200 Subject: [PATCH 06/30] Bugfix #3668 removed the comment --- modules/imgproc/src/filter.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/imgproc/src/filter.cpp b/modules/imgproc/src/filter.cpp index a55c1b0c6..6cdcf3cfb 100644 --- a/modules/imgproc/src/filter.cpp +++ b/modules/imgproc/src/filter.cpp @@ -454,8 +454,7 @@ void FilterEngine::apply(const Mat& src, Mat& dst, int y = start(src, srcRoi, isolated); proceed( src.data + y*src.step - + srcRoi.x*src.elemSize(),/* Bugfix #3668 use the x-shift of ROI - */ + + srcRoi.x*src.elemSize(), (int)src.step, endY - startY, dst.data + dstOfs.y*dst.step + dstOfs.x*dst.elemSize(), (int)dst.step ); From a9c7db75187d213935f4def5e70ccf7827c2a086 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Fri, 9 May 2014 13:44:12 +0200 Subject: [PATCH 07/30] add suggestion of feature 2619 --- .../linux_install/linux_install.rst | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/doc/tutorials/introduction/linux_install/linux_install.rst b/doc/tutorials/introduction/linux_install/linux_install.rst index 8e1409650..b0dcf6236 100644 --- a/doc/tutorials/introduction/linux_install/linux_install.rst +++ b/doc/tutorials/introduction/linux_install/linux_install.rst @@ -7,22 +7,24 @@ These steps have been tested for Ubuntu 10.04 but should work with other distros Required Packages ================= - * GCC 4.4.x or later. This can be installed with: + * GCC 4.4.x or later + * CMake 2.6 or higher + * Git + * GTK+2.x or higher, including headers (libgtk2.0-dev) + * pkg-config + * Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy) + * ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev + * [optional] libtbb2 libtbb-dev + * [optional] libdc1394 2.x + * [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev, libdc1394-22-dev + +The packages can be installed using a terminal and the following commands or by using Synaptic Manager: .. code-block:: bash - sudo apt-get install build-essential - - * CMake 2.6 or higher; - * Git; - * GTK+2.x or higher, including headers (libgtk2.0-dev); - * pkg-config; - * Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy); - * ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev; - * [optional] libdc1394 2.x; - * [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev. - -All the libraries above can be installed via Terminal or by using Synaptic Manager. + [compiler] sudo apt-get install build-essential + [required] sudo apt-get install cmake git libgtk2-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev + [optional] sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev Getting OpenCV Source Code ========================== From bb5a22c504bfa512cd8e40fc252947a5946ffc23 Mon Sep 17 00:00:00 2001 From: Luis Zarrabeitia Date: Sun, 11 May 2014 19:00:14 -0400 Subject: [PATCH 08/30] highgui: fix segfault on CvCapture_GStreamer::retrieveFrame CvCapture_GStreamer::retrieveFrame assumes that RGB videos are 24BPP. This is not necesarily the case, unless we explicitly tell GStreamer that we want 24BPP RGB streams. Adding bpp=(int)24 to the appsink caps. --- modules/highgui/src/cap_gstreamer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/highgui/src/cap_gstreamer.cpp b/modules/highgui/src/cap_gstreamer.cpp index cafc803db..72e19b16f 100644 --- a/modules/highgui/src/cap_gstreamer.cpp +++ b/modules/highgui/src/cap_gstreamer.cpp @@ -400,6 +400,7 @@ bool CvCapture_GStreamer::open( int type, const char* filename ) gst_app_sink_set_max_buffers (GST_APP_SINK(sink), 1); gst_app_sink_set_drop (GST_APP_SINK(sink), stream); caps = gst_caps_new_simple("video/x-raw-rgb", + "bpp", G_TYPE_INT, 24, "red_mask", G_TYPE_INT, 0x0000FF, "green_mask", G_TYPE_INT, 0x00FF00, "blue_mask", G_TYPE_INT, 0xFF0000, From e8376c789d675d9d4b536066320e2981b9981b49 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 8 May 2014 15:55:30 +0400 Subject: [PATCH 09/30] Fix non-Android cross compilation with OpenCVConfig.cmake --- cmake/templates/OpenCVConfig.cmake.in | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmake/templates/OpenCVConfig.cmake.in b/cmake/templates/OpenCVConfig.cmake.in index 3b011109a..6468aea5b 100644 --- a/cmake/templates/OpenCVConfig.cmake.in +++ b/cmake/templates/OpenCVConfig.cmake.in @@ -60,7 +60,11 @@ set(OpenCV_USE_CUFFT @HAVE_CUFFT@) set(OpenCV_USE_NVCUVID @HAVE_NVCUVID@) # Android API level from which OpenCV has been compiled is remembered -set(OpenCV_ANDROID_NATIVE_API_LEVEL @OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE@) +if(ANDROID) + set(OpenCV_ANDROID_NATIVE_API_LEVEL @OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE@) +else + set(OpenCV_ANDROID_NATIVE_API_LEVEL 0) +endif() # Some additional settings are required if OpenCV is built as static libs set(OpenCV_SHARED @BUILD_SHARED_LIBS@) @@ -71,8 +75,8 @@ set(OpenCV_USE_MANGLED_PATHS @OpenCV_USE_MANGLED_PATHS_CONFIGCMAKE@) # Extract the directory where *this* file has been installed (determined at cmake run-time) get_filename_component(OpenCV_CONFIG_PATH "${CMAKE_CURRENT_LIST_FILE}" PATH CACHE) -if(NOT WIN32 OR OpenCV_ANDROID_NATIVE_API_LEVEL GREATER 0) - if(OpenCV_ANDROID_NATIVE_API_LEVEL GREATER 0) +if(NOT WIN32 OR ANDROID) + if(ANDROID) set(OpenCV_INSTALL_PATH "${OpenCV_CONFIG_PATH}/../../..") else() set(OpenCV_INSTALL_PATH "${OpenCV_CONFIG_PATH}/../..") From 2b4241c10b2fb6ff410f5dc02b490f9d790f983d Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Mon, 12 May 2014 14:40:12 +0200 Subject: [PATCH 10/30] fixed bug 3484 --- .../doc/camera_calibration_and_3d_reconstruction.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst index 37159b016..721d74d2d 100644 --- a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst +++ b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst @@ -217,9 +217,9 @@ Computes useful camera characteristics from the camera matrix. :param imageSize: Input image size in pixels. - :param apertureWidth: Physical width of the sensor. + :param apertureWidth: Physical width in mm of the sensor. - :param apertureHeight: Physical height of the sensor. + :param apertureHeight: Physical height in mm of the sensor. :param fovx: Output field of view in degrees along the horizontal sensor axis. @@ -227,13 +227,15 @@ Computes useful camera characteristics from the camera matrix. :param focalLength: Focal length of the lens in mm. - :param principalPoint: Principal point in pixels. + :param principalPoint: Principal point in mm. :param aspectRatio: :math:`f_y/f_x` The function computes various useful camera characteristics from the previously estimated camera matrix. +.. note:: + Do keep in mind that the unity measure 'mm' stands for whatever unit of measure one chooses for the chessboard pitch (it can thus be any value). composeRT ------------- From b382984810e269ce7c94a8646c5985d044ebcf9b Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Mon, 12 May 2014 15:01:15 +0200 Subject: [PATCH 11/30] fix bug 3252 --- .../calib3d/doc/camera_calibration_and_3d_reconstruction.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst index 37159b016..d1c5d0662 100644 --- a/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst +++ b/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst @@ -1483,6 +1483,10 @@ Reconstructs points by triangulation. The function reconstructs 3-dimensional points (in homogeneous coordinates) by using their observations with a stereo camera. Projections matrices can be obtained from :ocv:func:`stereoRectify`. +.. note:: + + Keep in mind that all input data should be of float type in order for this function to work. + .. seealso:: :ocv:func:`reprojectImageTo3D` From e96de8821cbeaa28ebfea2035c52a70642c018ab Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Mon, 12 May 2014 15:26:56 +0200 Subject: [PATCH 12/30] bug 2740 added fix --- modules/nonfree/doc/feature_detection.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/nonfree/doc/feature_detection.rst b/modules/nonfree/doc/feature_detection.rst index 190c9f847..fec396a74 100644 --- a/modules/nonfree/doc/feature_detection.rst +++ b/modules/nonfree/doc/feature_detection.rst @@ -110,6 +110,8 @@ Detects keypoints and computes SURF descriptors for them. .. ocv:pyfunction:: cv2.SURF.detect(image[, mask]) -> keypoints +.. ocv:pyfunction:: cv2.SURF.detectAndCompute(image[, mask]) -> keypoints, descriptors + .. ocv:cfunction:: void cvExtractSURF( const CvArr* image, const CvArr* mask, CvSeq** keypoints, CvSeq** descriptors, CvMemStorage* storage, CvSURFParams params ) .. ocv:pyoldfunction:: cv.ExtractSURF(image, mask, storage, params)-> (keypoints, descriptors) From 6c59e39f7c120ebd56bd2236a02e35ac28a26736 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Mon, 12 May 2014 14:47:10 +0200 Subject: [PATCH 13/30] fix bug 3434 --- .../core/basic_linear_transform/basic_linear_transform.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tutorials/core/basic_linear_transform/basic_linear_transform.rst b/doc/tutorials/core/basic_linear_transform/basic_linear_transform.rst index 613f4e100..a641435f8 100644 --- a/doc/tutorials/core/basic_linear_transform/basic_linear_transform.rst +++ b/doc/tutorials/core/basic_linear_transform/basic_linear_transform.rst @@ -192,7 +192,7 @@ Explanation image.convertTo(new_image, -1, alpha, beta); - where :convert_to:`convertTo <>` would effectively perform *new_image = a*image + beta*. However, we wanted to show you how to access each pixel. In any case, both methods give the same result. + where :convert_to:`convertTo <>` would effectively perform *new_image = a*image + beta*. However, we wanted to show you how to access each pixel. In any case, both methods give the same result but convertTo is more optimized and works a lot faster. Result ======= From a0a8fb4fd92f1d99703970d0519ddca86eb4b411 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Mon, 12 May 2014 15:39:40 +0200 Subject: [PATCH 14/30] fixed bug 2626 --- modules/core/doc/drawing_functions.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/doc/drawing_functions.rst b/modules/core/doc/drawing_functions.rst index 7a6bd173a..f06d0fa60 100644 --- a/modules/core/doc/drawing_functions.rst +++ b/modules/core/doc/drawing_functions.rst @@ -514,7 +514,7 @@ Draws a text string. :param font: ``CvFont`` structure initialized using :ocv:cfunc:`InitFont`. :param fontFace: Font type. One of ``FONT_HERSHEY_SIMPLEX``, ``FONT_HERSHEY_PLAIN``, ``FONT_HERSHEY_DUPLEX``, ``FONT_HERSHEY_COMPLEX``, ``FONT_HERSHEY_TRIPLEX``, ``FONT_HERSHEY_COMPLEX_SMALL``, ``FONT_HERSHEY_SCRIPT_SIMPLEX``, or ``FONT_HERSHEY_SCRIPT_COMPLEX``, - where each of the font ID's can be combined with ``FONT_HERSHEY_ITALIC`` to get the slanted letters. + where each of the font ID's can be combined with ``FONT_ITALIC`` to get the slanted letters. :param fontScale: Font scale factor that is multiplied by the font-specific base size. From 6c118ebc514c805be3350c5fd1125933e0ddda18 Mon Sep 17 00:00:00 2001 From: 1Hyena Date: Mon, 12 May 2014 23:01:44 +0300 Subject: [PATCH 15/30] Changed ostringstream to ostream for new print_params and added the old version of print_params for backwards compatibility. --- modules/flann/include/opencv2/flann/params.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/flann/include/opencv2/flann/params.h b/modules/flann/include/opencv2/flann/params.h index 9ee5b1c9c..b40c39e3d 100644 --- a/modules/flann/include/opencv2/flann/params.h +++ b/modules/flann/include/opencv2/flann/params.h @@ -79,14 +79,19 @@ T get_param(const IndexParams& params, std::string name) } } -inline void print_params(const IndexParams& params, std::ostringstream& stream) +inline void print_params(const IndexParams& params, std::ostream& stream) { IndexParams::const_iterator it; + for(it=params.begin(); it!=params.end(); ++it) { stream << it->first << " : " << it->second << std::endl; } } +inline void print_params(const IndexParams& params) +{ + print_params(params, std::cout); +} } From 67b562d543154b29e3b5f8f9c79a03790da40712 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 13 May 2014 11:37:21 +0400 Subject: [PATCH 16/30] fix OpenCVConfig.cmake template - missing parentheses --- cmake/templates/OpenCVConfig.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/templates/OpenCVConfig.cmake.in b/cmake/templates/OpenCVConfig.cmake.in index 6468aea5b..6d1c1a990 100644 --- a/cmake/templates/OpenCVConfig.cmake.in +++ b/cmake/templates/OpenCVConfig.cmake.in @@ -62,7 +62,7 @@ set(OpenCV_USE_NVCUVID @HAVE_NVCUVID@) # Android API level from which OpenCV has been compiled is remembered if(ANDROID) set(OpenCV_ANDROID_NATIVE_API_LEVEL @OpenCV_ANDROID_NATIVE_API_LEVEL_CONFIGCMAKE@) -else +else() set(OpenCV_ANDROID_NATIVE_API_LEVEL 0) endif() From 006956c32435725e31e9aeb6bfe7035113249f73 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Mon, 12 May 2014 15:39:40 +0200 Subject: [PATCH 17/30] Fixing as suggested in bug 2626, made naming same for both C, C++ and python API --- modules/core/doc/operations_on_arrays.rst | 5 +++-- modules/core/include/opencv2/core/core.hpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/core/doc/operations_on_arrays.rst b/modules/core/doc/operations_on_arrays.rst index 8c01a1010..be91944e7 100644 --- a/modules/core/doc/operations_on_arrays.rst +++ b/modules/core/doc/operations_on_arrays.rst @@ -1252,11 +1252,12 @@ gemm ---- Performs generalized matrix multiplication. -.. ocv:function:: void gemm( InputArray src1, InputArray src2, double alpha, InputArray src3, double gamma, OutputArray dst, int flags=0 ) +.. ocv:function:: void gemm( InputArray src1, InputArray src2, double alpha, InputArray src3, double beta, OutputArray dst, int flags=0 ) -.. ocv:pyfunction:: cv2.gemm(src1, src2, alpha, src3, gamma[, dst[, flags]]) -> dst +.. ocv:pyfunction:: cv2.gemm(src1, src2, alpha, src3, beta[, dst[, flags]]) -> dst .. ocv:cfunction:: void cvGEMM( const CvArr* src1, const CvArr* src2, double alpha, const CvArr* src3, double beta, CvArr* dst, int tABC=0) + .. ocv:pyoldfunction:: cv.GEMM(src1, src2, alpha, src3, beta, dst, tABC=0)-> None :param src1: first multiplied input matrix that should have ``CV_32FC1``, ``CV_64FC1``, ``CV_32FC2``, or ``CV_64FC2`` type. diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 2ecb70c71..5667e9e50 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -2319,7 +2319,7 @@ CV_EXPORTS_W void patchNaNs(InputOutputArray a, double val=0); //! implements generalized matrix product algorithm GEMM from BLAS CV_EXPORTS_W void gemm(InputArray src1, InputArray src2, double alpha, - InputArray src3, double gamma, OutputArray dst, int flags=0); + InputArray src3, double beta, OutputArray dst, int flags=0); //! multiplies matrix by its transposition from the left or from the right CV_EXPORTS_W void mulTransposed( InputArray src, OutputArray dst, bool aTa, InputArray delta=noArray(), From 63e508abd2b3f85fe464a0bdbd1f9ce4515e5328 Mon Sep 17 00:00:00 2001 From: Kevin Mitchell Date: Mon, 12 May 2014 14:48:34 -0700 Subject: [PATCH 18/30] doc: update/clarify behaviour of mask in floodFill Clarify how the mask parameter is set on output and how this is affected by the flags parameter. resolves Feature #2942 --- modules/imgproc/doc/miscellaneous_transformations.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/imgproc/doc/miscellaneous_transformations.rst b/modules/imgproc/doc/miscellaneous_transformations.rst index e525f726d..7825a2458 100644 --- a/modules/imgproc/doc/miscellaneous_transformations.rst +++ b/modules/imgproc/doc/miscellaneous_transformations.rst @@ -504,7 +504,7 @@ Fills a connected component with the given color. :param image: Input/output 1- or 3-channel, 8-bit, or floating-point image. It is modified by the function unless the ``FLOODFILL_MASK_ONLY`` flag is set in the second variant of the function. See the details below. - :param mask: (For the second function only) Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller. The function uses and updates the mask, so you take responsibility of initializing the ``mask`` content. Flood-filling cannot go across non-zero pixels in the mask. For example, an edge detector output can be used as a mask to stop filling at edges. It is possible to use the same mask in multiple calls to the function to make sure the filled area does not overlap. + :param mask: Operation mask that should be a single-channel 8-bit image, 2 pixels wider and 2 pixels taller than ``image``. Since this is both an input and output parameter, you must take responsibility of initializing it. Flood-filling cannot go across non-zero pixels in the input mask. For example, an edge detector output can be used as a mask to stop filling at edges. On output, pixels in the mask corresponding to filled pixels in the image are set to 1 or to the a value specified in ``flags`` as described below. It is therefore possible to use the same mask in multiple calls to the function to make sure the filled areas do not overlap. .. note:: Since the mask is larger than the filled image, a pixel :math:`(x, y)` in ``image`` corresponds to the pixel :math:`(x+1, y+1)` in the ``mask`` . @@ -518,11 +518,11 @@ Fills a connected component with the given color. :param rect: Optional output parameter set by the function to the minimum bounding rectangle of the repainted domain. - :param flags: Operation flags. Lower bits contain a connectivity value, 4 (default) or 8, used within the function. Connectivity determines which neighbors of a pixel are considered. Upper bits can be 0 or a combination of the following flags: + :param flags: Operation flags. The first 8 bits contain a connectivity value. The default value of 4 means that only the four nearest neighbor pixels (those that share an edge) are considered. A connectivity value of 8 means that the eight nearest neighbor pixels (those that share a corner) will be considered. The next 8 bits (8-16) contain a value between 1 and 255 with which to fill the ``mask`` (the default value is 1). For example, ``4 | ( 255 << 8 )`` will consider 4 nearest neighbours and fill the mask with a value of 255. The following additional options occupy higher bits and therefore may be further combined with the connectivity and mask fill values using bit-wise or (``|``): * **FLOODFILL_FIXED_RANGE** If set, the difference between the current pixel and seed pixel is considered. Otherwise, the difference between neighbor pixels is considered (that is, the range is floating). - * **FLOODFILL_MASK_ONLY** If set, the function does not change the image ( ``newVal`` is ignored), but fills the mask. The flag can be used for the second variant only. + * **FLOODFILL_MASK_ONLY** If set, the function does not change the image ( ``newVal`` is ignored), and only fills the mask with the value specified in bits 8-16 of ``flags`` as described above. This option only make sense in function variants that have the ``mask`` parameter. The functions ``floodFill`` fill a connected component starting from the seed point with the specified color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The pixel at :math:`(x,y)` is considered to belong to the repainted domain if: From 1d557e6702c77ffba9a0ee9d255fc18c6d4248ef Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Tue, 13 May 2014 15:34:30 +0200 Subject: [PATCH 19/30] adding bugfix 3549 --- .../windows_visual_studio_image_watch.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.rst b/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.rst index 1337ff3a1..f7d7a1506 100644 --- a/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.rst +++ b/doc/tutorials/introduction/windows_visual_studio_image_watch/windows_visual_studio_image_watch.rst @@ -78,6 +78,8 @@ Make sure your active solution configuration (:menuselection:`Build --> Configur Build your solution (:menuselection:`Build --> Build Solution`, or press *F7*). +Before continuing, do not forget to add the command line argument of your input image to your project (:menuselection:`Right click on project --> Properties --> Configuration Properties --> Debugging` and then set the field ``Command Arguments`` with the location of the image). + Now set a breakpoint on the source line that says .. code-block:: c++ From 55a714c83bb366b6ad191681802e7ac1675c43dc Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Tue, 13 May 2014 17:59:20 +0400 Subject: [PATCH 20/30] fix cv::kmeans function reshape input matrix, since the function works with data as with [N x dims] matrix --- modules/core/src/matrix.cpp | 2 ++ samples/cpp/kmeans.cpp | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 517ee9dac..4b2d91e1d 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2701,6 +2701,8 @@ double cv::kmeans( InputArray _data, int K, CV_Assert( data.dims <= 2 && type == CV_32F && K > 0 ); CV_Assert( N >= K ); + data = data.reshape(1, N); + _bestLabels.create(N, 1, CV_32S, -1, true); Mat _labels, best_labels = _bestLabels.getMat(); diff --git a/samples/cpp/kmeans.cpp b/samples/cpp/kmeans.cpp index 19e998379..d475cf175 100644 --- a/samples/cpp/kmeans.cpp +++ b/samples/cpp/kmeans.cpp @@ -33,7 +33,7 @@ int main( int /*argc*/, char** /*argv*/ ) { int k, clusterCount = rng.uniform(2, MAX_CLUSTERS+1); int i, sampleCount = rng.uniform(1, 1001); - Mat points(sampleCount, 2, CV_32F), labels; + Mat points(sampleCount, 1, CV_32FC2), labels; clusterCount = MIN(clusterCount, sampleCount); Mat centers; From 6ecd553810c6c443bd92c12c9e2082e93fc9b1e8 Mon Sep 17 00:00:00 2001 From: Yash Vadalia Date: Sun, 11 May 2014 19:09:37 +0530 Subject: [PATCH 21/30] Added doc for LinearPolar Transform --- .../imgproc/doc/geometric_transformations.rst | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/modules/imgproc/doc/geometric_transformations.rst b/modules/imgproc/doc/geometric_transformations.rst index b3bb37c79..602610b2f 100644 --- a/modules/imgproc/doc/geometric_transformations.rst +++ b/modules/imgproc/doc/geometric_transformations.rst @@ -256,6 +256,57 @@ The function computes an inverse affine transformation represented by The result is also a :math:`2 \times 3` matrix of the same type as ``M`` . +LinearPolar +----------- +Remaps an image to polar space. + +.. ocv:cfunction:: void cvLinearPolar( const CvArr* src, CvArr* dst, CvPoint2D32f center, double maxRadius, int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS ) + + :param src: Source image + + :param dst: Destination image + + :param center: The transformation center; + + :param maxRadius: Inverse magnitude scale parameter. See below + + :param flags: A combination of interpolation methods and the following optional flags: + + * **CV_WARP_FILL_OUTLIERS** fills all of the destination image pixels. If some of them correspond to outliers in the source image, they are set to zero + + * **CV_WARP_INVERSE_MAP** See below + +The function ``cvLinearPolar`` transforms the source image using the following transformation: + + * + Forward transformation (``CV_WARP_INVERSE_MAP`` is not set): + + .. math:: + + dst( \phi , \rho ) = src(x,y) + + + * + Inverse transformation (``CV_WARP_INVERSE_MAP`` is set): + + .. math:: + + dst(x,y) = src( \phi , \rho ) + + +where + + .. math:: + + \rho = (src.width/maxRadius) \cdot \sqrt{x^2 + y^2} , \phi =atan(y/x) + + +The function can not operate in-place. + +.. note:: + + * An example using the LinearPolar operation can be found at opencv_source_code/samples/c/polar_transforms.c + LogPolar From 7e56cfafbce36ffe2ee3b85cf1ac6395d45804d3 Mon Sep 17 00:00:00 2001 From: Yash Vadalia Date: Tue, 13 May 2014 19:59:37 +0530 Subject: [PATCH 22/30] fixed a syntax error in cap_giganetix.cpp Ticket 3458 (http://code.opencv.org/issues/3458) --- modules/highgui/src/cap_giganetix.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/highgui/src/cap_giganetix.cpp b/modules/highgui/src/cap_giganetix.cpp index ccbe7020f..e252a1643 100644 --- a/modules/highgui/src/cap_giganetix.cpp +++ b/modules/highgui/src/cap_giganetix.cpp @@ -711,13 +711,13 @@ CvCaptureCAM_Giganetix::setProperty( int property_id, double value ) INT64 w, wmax, val = (INT64)value; if((b_ret = m_device->GetIntegerNodeValue ("Width", w))) if((b_ret = m_device->GetIntegerNodeValue ("WidthMax", wmax))) - b_ret = m_device->SetIntegerNodeValue ("OffsetX", val w > wmax ? wmax - w : val); + b_ret = m_device->SetIntegerNodeValue ("OffsetX", (val + w) > wmax ? (wmax - w) : val); } break; case CV_CAP_PROP_GIGA_FRAME_OFFSET_Y: { INT64 h, hmax, val = (INT64)value; if((b_ret = m_device->GetIntegerNodeValue ("Height", h))) if((b_ret = m_device->GetIntegerNodeValue ("HeightMax", hmax))) - b_ret = m_device->SetIntegerNodeValue ("OffsetY", val h > hmax ? hmax - h : val); + b_ret = m_device->SetIntegerNodeValue ("OffsetY", (val + h) > hmax ? (hmax - h) : val); b_ret = m_device->SetIntegerNodeValue ("OffsetY", (INT64)value); } break; From 1f72873c55a53772af64b0bc1f8611f1271be0e5 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 14 May 2014 10:31:28 +0400 Subject: [PATCH 23/30] fix cv::gpu::resize function add missing stream parameter to call_resize_linear_glob --- modules/gpu/src/cuda/resize.cu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gpu/src/cuda/resize.cu b/modules/gpu/src/cuda/resize.cu index 110e62d03..fa13121f9 100644 --- a/modules/gpu/src/cuda/resize.cu +++ b/modules/gpu/src/cuda/resize.cu @@ -213,7 +213,7 @@ namespace cv { namespace gpu { namespace device const dim3 block(32, 8); const dim3 grid(divUp(dst.cols, block.x), divUp(dst.rows, block.y)); - resize_linear<<>>(src, dst, fy, fx); + resize_linear<<>>(src, dst, fy, fx); cudaSafeCall( cudaGetLastError() ); if (stream == 0) From 7e2f7f45d7fe9d80bdc7cf38f8ed5e0a8a87bb09 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Wed, 14 May 2014 10:47:28 +0400 Subject: [PATCH 24/30] fix bug #3690 removed invalid condition, it is always false --- modules/ml/src/tree.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/ml/src/tree.cpp b/modules/ml/src/tree.cpp index 1ba94fcaf..8034fb099 100644 --- a/modules/ml/src/tree.cpp +++ b/modules/ml/src/tree.cpp @@ -1434,8 +1434,6 @@ void CvDTreeTrainData::read_params( CvFileStorage* fs, CvFileNode* node ) var_type->data.i[var_count] = cat_var_count; ord_var_count = ~ord_var_count; - if( cat_var_count != cat_var_count || ord_var_count != ord_var_count ) - CV_ERROR( CV_StsParseError, "var_type is inconsistent with cat_var_count and ord_var_count" ); ////// if( cat_var_count > 0 || is_classifier ) From 6a93b43caefe3cdb56085ebe47597fdcf7f9e689 Mon Sep 17 00:00:00 2001 From: Vlad Shakhuro Date: Thu, 8 May 2014 18:14:48 +0400 Subject: [PATCH 25/30] Fix svm intro tutorial --- doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst b/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst index 50f734803..574071de7 100644 --- a/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst +++ b/doc/tutorials/ml/introduction_to_svm/introduction_to_svm.rst @@ -105,8 +105,8 @@ Explanation .. code-block:: cpp - Mat trainingDataMat(3, 2, CV_32FC1, trainingData); - Mat labelsMat (3, 1, CV_32FC1, labels); + Mat trainingDataMat(4, 2, CV_32FC1, trainingData); + Mat labelsMat (4, 1, CV_32FC1, labels); 2. **Set up SVM's parameters** From ea038436e6b115b783212976b57b4f1455c8ac7b Mon Sep 17 00:00:00 2001 From: thoinvil Date: Thu, 15 May 2014 08:40:13 +0200 Subject: [PATCH 26/30] Added condition to 1st test in cv::GaussianBlur Consistent with the test made in cv::boxFilter, it adjusts the kernel size to the source size only if the border is not BORDER_CONSTANT and if BORDER_ISOLATED is set. Otherwise, the source has to be considered possibly in a larger image (i.e. the source being a ROI) in witch the kernel should apply. --- modules/imgproc/src/smooth.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/imgproc/src/smooth.cpp b/modules/imgproc/src/smooth.cpp index ae14ca9e1..c0ea05ea2 100644 --- a/modules/imgproc/src/smooth.cpp +++ b/modules/imgproc/src/smooth.cpp @@ -837,7 +837,7 @@ void cv::GaussianBlur( InputArray _src, OutputArray _dst, Size ksize, _dst.create( src.size(), src.type() ); Mat dst = _dst.getMat(); - if( borderType != BORDER_CONSTANT ) + if( borderType != BORDER_CONSTANT && (borderType & BORDER_ISOLATED) != 0 ) { if( src.rows == 1 ) ksize.height = 1; From f16503743f98c6a49d9506095d7f4ab143131f25 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 15 May 2014 12:08:01 +0400 Subject: [PATCH 27/30] use more accurate reshape --- modules/core/src/matrix.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 4b2d91e1d..8e32b0fbe 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2691,17 +2691,17 @@ double cv::kmeans( InputArray _data, int K, int flags, OutputArray _centers ) { const int SPP_TRIALS = 3; - Mat data = _data.getMat(); - bool isrow = data.rows == 1 && data.channels() > 1; - int N = !isrow ? data.rows : data.cols; - int dims = (!isrow ? data.cols : 1)*data.channels(); - int type = data.depth(); + Mat data0 = _data.getMat(); + bool isrow = data0.rows == 1 && data0.channels() > 1; + int N = !isrow ? data0.rows : data0.cols; + int dims = (!isrow ? data0.cols : 1)*data0.channels(); + int type = data0.depth(); attempts = std::max(attempts, 1); - CV_Assert( data.dims <= 2 && type == CV_32F && K > 0 ); + CV_Assert( data0.dims <= 2 && type == CV_32F && K > 0 ); CV_Assert( N >= K ); - data = data.reshape(1, N); + Mat data(N, dims, CV_32F, data0.data, isrow ? dims * sizeof(float) : static_cast(data0.step)); _bestLabels.create(N, 1, CV_32S, -1, true); From 746185652a3c55e32b74ed9914b9e8c98aa09079 Mon Sep 17 00:00:00 2001 From: Vladislav Vinogradov Date: Thu, 15 May 2014 12:08:38 +0400 Subject: [PATCH 28/30] add additional tests for different input cases --- modules/core/test/test_math.cpp | 91 +++++++++++++++++++++++++++++---- 1 file changed, 81 insertions(+), 10 deletions(-) diff --git a/modules/core/test/test_math.cpp b/modules/core/test/test_math.cpp index a572cd0d9..5dec97e8c 100644 --- a/modules/core/test/test_math.cpp +++ b/modules/core/test/test_math.cpp @@ -2512,6 +2512,15 @@ TEST(Core_SVD, flt) // TODO: eigenvv, invsqrt, cbrt, fastarctan, (round, floor, ceil(?)), +enum +{ + MAT_N_DIM_C1, + MAT_N_1_CDIM, + MAT_1_N_CDIM, + MAT_N_DIM_C1_NONCONT, + MAT_N_1_CDIM_NONCONT, + VECTOR +}; class CV_KMeansSingularTest : public cvtest::BaseTest { @@ -2519,7 +2528,7 @@ public: CV_KMeansSingularTest() {} ~CV_KMeansSingularTest() {} protected: - void run(int) + void run(int inVariant) { int i, iter = 0, N = 0, N0 = 0, K = 0, dims = 0; Mat labels; @@ -2531,20 +2540,70 @@ protected: for( iter = 0; iter < maxIter; iter++ ) { ts->update_context(this, iter, true); - dims = rng.uniform(1, MAX_DIM+1); + dims = rng.uniform(inVariant == MAT_1_N_CDIM ? 2 : 1, MAX_DIM+1); N = rng.uniform(1, MAX_POINTS+1); N0 = rng.uniform(1, MAX(N/10, 2)); K = rng.uniform(1, N+1); - Mat data0(N0, dims, CV_32F); - rng.fill(data0, RNG::UNIFORM, -1, 1); + if (inVariant == VECTOR) + { + dims = 2; - Mat data(N, dims, CV_32F); - for( i = 0; i < N; i++ ) - data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); + std::vector data0(N0); + rng.fill(data0, RNG::UNIFORM, -1, 1); - kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), - 5, KMEANS_PP_CENTERS); + std::vector data(N); + for( i = 0; i < N; i++ ) + data[i] = data0[rng.uniform(0, N0)]; + + kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), + 5, KMEANS_PP_CENTERS); + } + else + { + Mat data0(N0, dims, CV_32F); + rng.fill(data0, RNG::UNIFORM, -1, 1); + + Mat data; + + switch (inVariant) + { + case MAT_N_DIM_C1: + data.create(N, dims, CV_32F); + for( i = 0; i < N; i++ ) + data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); + break; + + case MAT_N_1_CDIM: + data.create(N, 1, CV_32FC(dims)); + for( i = 0; i < N; i++ ) + memcpy(data.ptr(i), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); + break; + + case MAT_1_N_CDIM: + data.create(1, N, CV_32FC(dims)); + for( i = 0; i < N; i++ ) + memcpy(data.data + i * dims * sizeof(float), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); + break; + + case MAT_N_DIM_C1_NONCONT: + data.create(N, dims + 5, CV_32F); + data = data(Range(0, N), Range(0, dims)); + for( i = 0; i < N; i++ ) + data0.row(rng.uniform(0, N0)).copyTo(data.row(i)); + break; + + case MAT_N_1_CDIM_NONCONT: + data.create(N, 3, CV_32FC(dims)); + data = data.colRange(0, 1); + for( i = 0; i < N; i++ ) + memcpy(data.ptr(i), data0.ptr(rng.uniform(0, N0)), dims * sizeof(float)); + break; + } + + kmeans(data, K, labels, TermCriteria(TermCriteria::MAX_ITER+TermCriteria::EPS, 30, 0), + 5, KMEANS_PP_CENTERS); + } Mat hist(K, 1, CV_32S, Scalar(0)); for( i = 0; i < N; i++ ) @@ -2568,7 +2627,19 @@ protected: } }; -TEST(Core_KMeans, singular) { CV_KMeansSingularTest test; test.safe_run(); } +TEST(Core_KMeans, singular) { CV_KMeansSingularTest test; test.safe_run(MAT_N_DIM_C1); } + +CV_ENUM(KMeansInputVariant, MAT_N_DIM_C1, MAT_N_1_CDIM, MAT_1_N_CDIM, MAT_N_DIM_C1_NONCONT, MAT_N_1_CDIM_NONCONT, VECTOR) + +typedef testing::TestWithParam Core_KMeans_InputVariants; + +TEST_P(Core_KMeans_InputVariants, singular) +{ + CV_KMeansSingularTest test; + test.safe_run(GetParam()); +} + +INSTANTIATE_TEST_CASE_P(AllVariants, Core_KMeans_InputVariants, KMeansInputVariant::all()); TEST(CovariationMatrixVectorOfMat, accuracy) { From 7fc764f5e5c9470db40eebe2662fa2a84034a1f2 Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Mon, 12 May 2014 16:45:42 +0200 Subject: [PATCH 29/30] added documentation for findContours --- .../imgproc/doc/structural_analysis_and_shape_descriptors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst b/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst index de4e585d8..29e8b9857 100644 --- a/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst +++ b/modules/imgproc/doc/structural_analysis_and_shape_descriptors.rst @@ -133,7 +133,7 @@ Finds contours in a binary image. .. ocv:pyoldfunction:: cv.FindContours(image, storage, mode=CV_RETR_LIST, method=CV_CHAIN_APPROX_SIMPLE, offset=(0, 0)) -> contours - :param image: Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero pixels remain 0's, so the image is treated as ``binary`` . You can use :ocv:func:`compare` , :ocv:func:`inRange` , :ocv:func:`threshold` , :ocv:func:`adaptiveThreshold` , :ocv:func:`Canny` , and others to create a binary image out of a grayscale or color one. The function modifies the ``image`` while extracting the contours. + :param image: Source, an 8-bit single-channel image. Non-zero pixels are treated as 1's. Zero pixels remain 0's, so the image is treated as ``binary`` . You can use :ocv:func:`compare` , :ocv:func:`inRange` , :ocv:func:`threshold` , :ocv:func:`adaptiveThreshold` , :ocv:func:`Canny` , and others to create a binary image out of a grayscale or color one. The function modifies the ``image`` while extracting the contours. If mode equals to ``CV_RETR_CCOMP`` or ``CV_RETR_FLOODFILL``, the input can also be a 32-bit integer image of labels (``CV_32SC1``). :param contours: Detected contours. Each contour is stored as a vector of points. From 12207ac7630eaf06b357131af0a0350ffa0802aa Mon Sep 17 00:00:00 2001 From: StevenPuttemans Date: Tue, 13 May 2014 11:43:02 +0200 Subject: [PATCH 30/30] fix coordinate problem with large images - bug 1523 --- modules/highgui/src/window_w32.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/modules/highgui/src/window_w32.cpp b/modules/highgui/src/window_w32.cpp index 48f3aab23..b5cbc5565 100644 --- a/modules/highgui/src/window_w32.cpp +++ b/modules/highgui/src/window_w32.cpp @@ -1436,8 +1436,6 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM if( window->on_mouse ) { POINT pt; - RECT rect; - SIZE size = {0,0}; int flags = (wParam & MK_LBUTTON ? CV_EVENT_FLAG_LBUTTON : 0)| (wParam & MK_RBUTTON ? CV_EVENT_FLAG_RBUTTON : 0)| @@ -1463,12 +1461,23 @@ static LRESULT CALLBACK HighGUIProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM pt.x = GET_X_LPARAM( lParam ); pt.y = GET_Y_LPARAM( lParam ); - GetClientRect( window->hwnd, &rect ); - icvGetBitmapData( window, &size, 0, 0 ); + if (window->flags & CV_WINDOW_AUTOSIZE) + { + // As user can't change window size, do not scale window coordinates. Underlying windowing system + // may prevent full window from being displayed and in this case coordinates should not be scaled. + window->on_mouse( event, pt.x, pt.y, flags, window->on_mouse_param ); + } else { + // Full window is displayed using different size. Scale coordinates to match underlying positions. + RECT rect; + SIZE size = {0, 0}; - window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1), - pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags, - window->on_mouse_param ); + GetClientRect( window->hwnd, &rect ); + icvGetBitmapData( window, &size, 0, 0 ); + + window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1), + pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags, + window->on_mouse_param ); + } } break;