From 9944282b0993c5474cf30a108a369e56c600d75d Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Fri, 21 Dec 2012 19:58:51 +0400 Subject: [PATCH 1/5] Fix build with STLPort from NDK r8d --- modules/androidcamera/src/camera_activity.cpp | 23 ++++++++++--------- modules/contrib/src/chamfermatching.cpp | 4 ++-- modules/contrib/src/spinimages.cpp | 2 +- modules/core/include/opencv2/core/core.hpp | 2 +- .../core/include/opencv2/core/operations.hpp | 3 ++- modules/features2d/src/keypoint.cpp | 6 ++--- modules/features2d/src/matchers.cpp | 6 ++--- modules/features2d/src/precomp.hpp | 2 ++ modules/stitching/src/autocalib.cpp | 2 +- modules/stitching/src/stitcher.cpp | 2 +- modules/ts/include/opencv2/ts/ts_gtest.h | 11 ++++++--- modules/videostab/src/inpainting.cpp | 2 +- samples/c/facedetect.cpp | 1 + samples/cpp/bagofwords_classification.cpp | 4 ++-- samples/cpp/calibration.cpp | 2 ++ samples/cpp/point_cloud.cpp | 2 ++ .../how_to_scan_images/how_to_scan_images.cpp | 4 ++-- samples/cpp/videostab.cpp | 2 +- 18 files changed, 47 insertions(+), 33 deletions(-) diff --git a/modules/androidcamera/src/camera_activity.cpp b/modules/androidcamera/src/camera_activity.cpp index 28e18c479e..37144ba1a2 100644 --- a/modules/androidcamera/src/camera_activity.cpp +++ b/modules/androidcamera/src/camera_activity.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -303,8 +304,8 @@ std::string CameraWrapperConnector::getPathLibFolder() LOGD("Library name: %s", dl_info.dli_fname); LOGD("Library base address: %p", dl_info.dli_fbase); - const char* libName=dl_info.dli_fname; - while( ((*libName)=='/') || ((*libName)=='.') ) + const char* libName=dl_info.dli_fname; + while( ((*libName)=='/') || ((*libName)=='.') ) libName++; char lineBuf[2048]; @@ -312,9 +313,9 @@ std::string CameraWrapperConnector::getPathLibFolder() if(file) { - while (fgets(lineBuf, sizeof lineBuf, file) != NULL) - { - //verify that line ends with library name + while (fgets(lineBuf, sizeof lineBuf, file) != NULL) + { + //verify that line ends with library name int lineLength = strlen(lineBuf); int libNameLength = strlen(libName); @@ -327,7 +328,7 @@ std::string CameraWrapperConnector::getPathLibFolder() if (0 != strncmp(lineBuf + lineLength - libNameLength, libName, libNameLength)) { - //the line does not contain the library name + //the line does not contain the library name continue; } @@ -346,18 +347,18 @@ std::string CameraWrapperConnector::getPathLibFolder() fclose(file); return pathBegin; - } - fclose(file); - LOGE("Could not find library path"); + } + fclose(file); + LOGE("Could not find library path"); } else { - LOGE("Could not read /proc/self/smaps"); + LOGE("Could not read /proc/self/smaps"); } } else { - LOGE("Could not get library name and base address"); + LOGE("Could not get library name and base address"); } return string(); diff --git a/modules/contrib/src/chamfermatching.cpp b/modules/contrib/src/chamfermatching.cpp index 052189e515..d33b243a59 100644 --- a/modules/contrib/src/chamfermatching.cpp +++ b/modules/contrib/src/chamfermatching.cpp @@ -767,8 +767,8 @@ void ChamferMatcher::Matching::findContourOrientations(const template_coords_t& } // get the middle two angles - nth_element(angles.begin(), angles.begin()+M-1, angles.end()); - nth_element(angles.begin()+M-1, angles.begin()+M, angles.end()); + std::nth_element(angles.begin(), angles.begin()+M-1, angles.end()); + std::nth_element(angles.begin()+M-1, angles.begin()+M, angles.end()); // sort(angles.begin(), angles.end()); // average them to compute tangent diff --git a/modules/contrib/src/spinimages.cpp b/modules/contrib/src/spinimages.cpp index 46b22c8c31..21cbc8b9fb 100644 --- a/modules/contrib/src/spinimages.cpp +++ b/modules/contrib/src/spinimages.cpp @@ -85,7 +85,7 @@ namespace }; size_t colors_mum = sizeof(colors)/sizeof(colors[0]); -#if defined __cplusplus && __cplusplus > 199711L +#if (defined __cplusplus && __cplusplus > 199711L) || defined _STLPORT_MAJOR #else template void iota(FwIt first, FwIt last, T value) { while(first != last) *first++ = value++; } #endif diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 0454cf4e96..8cf8f28c10 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -4655,7 +4655,7 @@ class CV_EXPORTS CommandLineParser template static _Tp getData(const std::string& str) { - _Tp res; + _Tp res = _Tp(); std::stringstream s1(str); s1 >> res; return res; diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index a9031749da..fc40f5724b 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -65,7 +65,8 @@ #elif __GNUC__*10 + __GNUC_MINOR__ >= 42 #if !(defined WIN32 || defined _WIN32) && (defined __i486__ || defined __i586__ || \ - defined __i686__ || defined __MMX__ || defined __SSE__ || defined __ppc__) + defined __i686__ || defined __MMX__ || defined __SSE__ || defined __ppc__) || \ + (defined __GNUC__ && defined _STLPORT_MAJOR) #define CV_XADD __sync_fetch_and_add #else #include diff --git a/modules/features2d/src/keypoint.cpp b/modules/features2d/src/keypoint.cpp index 922a8e5e5f..9b85fd39c0 100644 --- a/modules/features2d/src/keypoint.cpp +++ b/modules/features2d/src/keypoint.cpp @@ -232,7 +232,7 @@ void KeyPointsFilter::runByImageBorder( vector& keypoints, Size imageS if (imageSize.height <= borderSize * 2 || imageSize.width <= borderSize * 2) keypoints.clear(); else - keypoints.erase( remove_if(keypoints.begin(), keypoints.end(), + keypoints.erase( std::remove_if(keypoints.begin(), keypoints.end(), RoiPredicate(Rect(Point(borderSize, borderSize), Point(imageSize.width - borderSize, imageSize.height - borderSize)))), keypoints.end() ); @@ -259,7 +259,7 @@ void KeyPointsFilter::runByKeypointSize( vector& keypoints, float minS CV_Assert( maxSize >= 0); CV_Assert( minSize <= maxSize ); - keypoints.erase( remove_if(keypoints.begin(), keypoints.end(), SizePredicate(minSize, maxSize)), + keypoints.erase( std::remove_if(keypoints.begin(), keypoints.end(), SizePredicate(minSize, maxSize)), keypoints.end() ); } @@ -282,7 +282,7 @@ void KeyPointsFilter::runByPixelsMask( vector& keypoints, const Mat& m if( mask.empty() ) return; - keypoints.erase(remove_if(keypoints.begin(), keypoints.end(), MaskPredicate(mask)), keypoints.end()); + keypoints.erase(std::remove_if(keypoints.begin(), keypoints.end(), MaskPredicate(mask)), keypoints.end()); } struct KeyPoint_LessThan diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 091feaaa8a..40612f8eeb 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -77,7 +77,7 @@ DescriptorMatcher::DescriptorCollection::DescriptorCollection() DescriptorMatcher::DescriptorCollection::DescriptorCollection( const DescriptorCollection& collection ) { mergedDescriptors = collection.mergedDescriptors.clone(); - copy( collection.startIdxs.begin(), collection.startIdxs.begin(), startIdxs.begin() ); + std::copy( collection.startIdxs.begin(), collection.startIdxs.begin(), startIdxs.begin() ); } DescriptorMatcher::DescriptorCollection::~DescriptorCollection() @@ -807,9 +807,9 @@ GenericDescriptorMatcher::KeyPointCollection::KeyPointCollection( const KeyPoint keypoints.resize( collection.keypoints.size() ); for( size_t i = 0; i < keypoints.size(); i++ ) - copy( collection.keypoints[i].begin(), collection.keypoints[i].end(), keypoints[i].begin() ); + std::copy( collection.keypoints[i].begin(), collection.keypoints[i].end(), keypoints[i].begin() ); - copy( collection.startIndices.begin(), collection.startIndices.end(), startIndices.begin() ); + std::copy( collection.startIndices.begin(), collection.startIndices.end(), startIndices.begin() ); } void GenericDescriptorMatcher::KeyPointCollection::add( const vector& _images, diff --git a/modules/features2d/src/precomp.hpp b/modules/features2d/src/precomp.hpp index c1e3ace7a5..cbc1eb690a 100644 --- a/modules/features2d/src/precomp.hpp +++ b/modules/features2d/src/precomp.hpp @@ -52,6 +52,8 @@ #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/core/internal.hpp" +#include + #ifdef HAVE_TEGRA_OPTIMIZATION #include "opencv2/features2d/features2d_tegra.hpp" #endif diff --git a/modules/stitching/src/autocalib.cpp b/modules/stitching/src/autocalib.cpp index a07ec9e4af..0314b27698 100644 --- a/modules/stitching/src/autocalib.cpp +++ b/modules/stitching/src/autocalib.cpp @@ -122,7 +122,7 @@ void estimateFocal(const vector &features, const vector(focals[focals.size() / 2]); else diff --git a/modules/ts/include/opencv2/ts/ts_gtest.h b/modules/ts/include/opencv2/ts/ts_gtest.h index 585650ff03..f26059111f 100644 --- a/modules/ts/include/opencv2/ts/ts_gtest.h +++ b/modules/ts/include/opencv2/ts/ts_gtest.h @@ -564,7 +564,7 @@ # define GTEST_HAS_RTTI 0 # else # define GTEST_HAS_RTTI 1 -# endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS +# endif // GTEST_OS_LINUX_ANDROID && _STLPORT_MAJOR && !__EXCEPTIONS # else # define GTEST_HAS_RTTI 0 # endif // __GXX_RTTI @@ -650,8 +650,11 @@ // support TR1 tuple. libc++ only provides std::tuple, in C++11 mode, // and it can be used with some compilers that define __GNUC__. # if (defined(__GNUC__) && !defined(__CUDACC__) && (GTEST_GCC_VER_ >= 40000) \ - && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) || _MSC_VER >= 1600 + && !GTEST_OS_QNX && !defined(_LIBCPP_VERSION)) && !defined(_STLPORT_MAJOR) \ + || (defined(_MSC_VER) && _MSC_VER >= 1600) # define GTEST_ENV_HAS_TR1_TUPLE_ 1 +# else +# define GTEST_ENV_HAS_TR1_TUPLE_ 0 # endif // C++11 specifies that provides std::tuple. Use that if gtest is used @@ -659,7 +662,7 @@ // can build with clang but need to use gcc4.2's libstdc++). # if GTEST_LANG_CXX11 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20110325) # define GTEST_ENV_HAS_STD_TUPLE_ 1 -#else +# else # define GTEST_ENV_HAS_STD_TUPLE_ 0 # endif @@ -667,6 +670,8 @@ # define GTEST_USE_OWN_TR1_TUPLE 0 # else # define GTEST_USE_OWN_TR1_TUPLE 1 +# undef GTEST_HAS_TR1_TUPLE +# define GTEST_HAS_TR1_TUPLE 1 # endif #endif // GTEST_USE_OWN_TR1_TUPLE diff --git a/modules/videostab/src/inpainting.cpp b/modules/videostab/src/inpainting.cpp index 1a81c411cf..4377c007c8 100644 --- a/modules/videostab/src/inpainting.cpp +++ b/modules/videostab/src/inpainting.cpp @@ -172,7 +172,7 @@ void ConsistentMosaicInpainter::inpaint(int idx, Mat &frame, Mat &mask) if (var < stdevThresh_ * stdevThresh_) { - sort(pixels.begin(), pixels.begin() + n); + std::sort(pixels.begin(), pixels.begin() + n); int nh = (n-1)/2; int c1 = pixels[nh].color.x; int c2 = pixels[nh].color.y; diff --git a/samples/c/facedetect.cpp b/samples/c/facedetect.cpp index 60b3a57bda..a7d7f4adba 100644 --- a/samples/c/facedetect.cpp +++ b/samples/c/facedetect.cpp @@ -2,6 +2,7 @@ #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" +#include #include #include #include diff --git a/samples/cpp/bagofwords_classification.cpp b/samples/cpp/bagofwords_classification.cpp index 30cc70bb54..e24a770f8e 100644 --- a/samples/cpp/bagofwords_classification.cpp +++ b/samples/cpp/bagofwords_classification.cpp @@ -1453,7 +1453,7 @@ void VocData::readClassifierGroundTruth(const string& filename, vector& string line; string image; - int obj_present; + int obj_present = 0; while (!gtfile.eof()) { std::getline(gtfile,line); @@ -1826,7 +1826,7 @@ void VocData::readFileToString(const string filename, string& file_contents) int VocData::stringToInteger(const string input_str) { - int result; + int result = 0; stringstream ss(input_str); if ((ss >> result).fail()) diff --git a/samples/cpp/calibration.cpp b/samples/cpp/calibration.cpp index 826e54902a..f4ff81077b 100644 --- a/samples/cpp/calibration.cpp +++ b/samples/cpp/calibration.cpp @@ -2,6 +2,8 @@ #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/calib3d/calib3d.hpp" #include "opencv2/highgui/highgui.hpp" + +#include #include #include #include diff --git a/samples/cpp/point_cloud.cpp b/samples/cpp/point_cloud.cpp index 28e9173388..2780df38e7 100644 --- a/samples/cpp/point_cloud.cpp +++ b/samples/cpp/point_cloud.cpp @@ -1,7 +1,9 @@ +#include #include #include #include #include + #include "opencv2/core/core.hpp" #include "opencv2/core/opengl_interop.hpp" #include "opencv2/highgui/highgui.hpp" diff --git a/samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp b/samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp index defc23fd78..49aca426e1 100644 --- a/samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp +++ b/samples/cpp/tutorial_code/core/how_to_scan_images/how_to_scan_images.cpp @@ -45,11 +45,11 @@ int main( int argc, char* argv[]) return -1; } - int divideWith; // convert our input string to number - C++ style + int divideWith = 0; // convert our input string to number - C++ style stringstream s; s << argv[2]; s >> divideWith; - if (!s) + if (!s || !divideWith) { cout << "Invalid number entered for dividing. " << endl; return -1; diff --git a/samples/cpp/videostab.cpp b/samples/cpp/videostab.cpp index 6a6ed1c554..bd4e8533f4 100644 --- a/samples/cpp/videostab.cpp +++ b/samples/cpp/videostab.cpp @@ -32,7 +32,7 @@ public: ifstream f(path.c_str()); if (!f.is_open()) throw runtime_error("can't open motions file: " + path); - int size; f >> size; + int size = 0; f >> size; motions_.resize(size); for (int i = 0; i < size; ++i) { From f87987ed72dce109135d093b733d5296efc6e404 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Sat, 22 Dec 2012 17:56:02 +0400 Subject: [PATCH 2/5] Honor multidimensional matrices in InputArray::total --- modules/core/src/matrix.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 5ea21cf8a1..7b58debfc7 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -1188,6 +1188,24 @@ Size _InputArray::size(int i) const size_t _InputArray::total(int i) const { + int k = kind(); + + if( k == MAT ) + { + CV_Assert( i < 0 ); + return ((const Mat*)obj)->total(); + } + + if( k == STD_VECTOR_MAT ) + { + const vector& vv = *(const vector*)obj; + if( i < 0 ) + return vv.size(); + + CV_Assert( i < (int)vv.size() ); + return vv[i].total(); + } + return size(i).area(); } From b870b246e106bedff4a7e9fd0cd45b9c1f394dd5 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Sat, 22 Dec 2012 21:01:57 +0400 Subject: [PATCH 3/5] Fix memory corruption in batchDistance perf tests --- modules/features2d/perf/perf_batchDistance.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/features2d/perf/perf_batchDistance.cpp b/modules/features2d/perf/perf_batchDistance.cpp index 157b59fb4a..75a2aa1f40 100644 --- a/modules/features2d/perf/perf_batchDistance.cpp +++ b/modules/features2d/perf/perf_batchDistance.cpp @@ -150,7 +150,7 @@ void generateData( Mat& query, Mat& train, const int sourceType ) // in ascending order. General boundaries of the perturbation // are (0.f, 1.f). train.create( query.rows*countFactor, query.cols, sourceType ); - float step = 1.f / countFactor; + float step = (sourceType == CV_8U ? 256.f : 1.f) / countFactor; for( int qIdx = 0; qIdx < query.rows; qIdx++ ) { Mat queryDescriptor = query.row(qIdx); @@ -161,7 +161,7 @@ void generateData( Mat& query, Mat& train, const int sourceType ) queryDescriptor.copyTo( trainDescriptor ); int elem = rng(dim); float diff = rng.uniform( step*c, step*(c+1) ); - trainDescriptor.at(0, elem) += diff; + trainDescriptor.col(elem) += diff; } } } From d6d1d208160311cdf352162a0dd922b903d289f3 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Sat, 22 Dec 2012 22:52:27 +0400 Subject: [PATCH 4/5] Show STL type in CMake status report --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c3932a012..4ca9d17186 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -565,6 +565,7 @@ if(ANDROID) status("") status(" Android: ") status(" Android ABI:" ${ANDROID_ABI}) + status(" STL type:" ${ANDROID_STL}) status(" Native API level:" android-${ANDROID_NATIVE_API_LEVEL}) status(" SDK target:" "${ANDROID_SDK_TARGET}") if(BUILD_WITH_ANDROID_NDK) From 20838b6f6e1311aa90dd001ab05f091610dcf0a1 Mon Sep 17 00:00:00 2001 From: Alexander Mordvintsev Date: Fri, 21 Dec 2012 16:58:26 +0400 Subject: [PATCH 5/5] fix #2643: use SVD to solve least squares in cvStereoRectifyUncalibrated --- modules/calib3d/src/calibration.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index edb109beb1..62a1c3c006 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -2778,17 +2778,13 @@ CV_IMPL int cvStereoRectifyUncalibrated( cvPerspectiveTransform( _m1, _m1, &H0 ); cvPerspectiveTransform( _m2, _m2, &H2 ); CvMat A = cvMat( 1, npoints, CV_64FC3, lines1 ), BxBy, B; - double a[9], atb[3], x[3]; - CvMat AtA = cvMat( 3, 3, CV_64F, a ); - CvMat AtB = cvMat( 3, 1, CV_64F, atb ); + double x[3]; CvMat X = cvMat( 3, 1, CV_64F, x ); cvConvertPointsHomogeneous( _m1, &A ); cvReshape( &A, &A, 1, npoints ); cvReshape( _m2, &BxBy, 1, npoints ); cvGetCol( &BxBy, &B, 0 ); - cvGEMM( &A, &A, 1, 0, 0, &AtA, CV_GEMM_A_T ); - cvGEMM( &A, &B, 1, 0, 0, &AtB, CV_GEMM_A_T ); - cvSolve( &AtA, &AtB, &X, CV_SVD_SYM ); + cvSolve( &A, &B, &X, CV_SVD ); double ha[] = {