From 94c310fc14fef8a8d0bbca6f4e5e26212bfba124 Mon Sep 17 00:00:00 2001 From: Anatoly Baksheev Date: Sat, 15 Dec 2012 22:09:21 +0400 Subject: [PATCH] added Ptr::operator== --- modules/core/include/opencv2/core/core.hpp | 2 ++ modules/core/include/opencv2/core/operations.hpp | 5 +++++ modules/features2d/perf/perf_fast.cpp | 2 +- modules/features2d/src/matchers.cpp | 4 ++-- modules/stitching/src/matchers.cpp | 2 +- modules/video/test/test_backgroundsubtractor_gbh.cpp | 2 +- 6 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 60d9d013c8..cfeaea5475 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -1284,6 +1284,8 @@ public: operator _Tp* (); operator const _Tp*() const; + bool operator==(const Ptr<_Tp>& ptr) const; + _Tp* obj; //< the object pointer. int* refcount; //< the associated reference counter }; diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index e3ebe6e675..34bf5e0baa 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -2690,6 +2690,11 @@ template template inline const Ptr<_Tp2> Ptr<_Tp>:: return p; } +template inline bool Ptr<_Tp>::operator==(const Ptr<_Tp>& _ptr) const +{ + return refcount == _ptr.refcount; +} + //// specializied implementations of Ptr::delete_obj() for classic OpenCV types template<> CV_EXPORTS void Ptr::delete_obj(); diff --git a/modules/features2d/perf/perf_fast.cpp b/modules/features2d/perf/perf_fast.cpp index a7793884f7..d7bcb41e0b 100644 --- a/modules/features2d/perf/perf_fast.cpp +++ b/modules/features2d/perf/perf_fast.cpp @@ -31,7 +31,7 @@ PERF_TEST_P(fast, detect, testing::Combine( declare.in(frame); Ptr fd = Algorithm::create("Feature2D.FAST"); - ASSERT_FALSE( fd == 0 ); + ASSERT_FALSE( fd.empty() ); fd->set("threshold", 20); fd->set("nonmaxSuppression", true); fd->set("type", type); diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 091feaaa8a..fbcbcf082f 100644 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -531,7 +531,7 @@ void FlannBasedMatcher::train() void FlannBasedMatcher::read( const FileNode& fn) { - if (indexParams == 0) + if (indexParams.empty()) indexParams = new flann::IndexParams(); FileNode ip = fn["indexParams"]; @@ -570,7 +570,7 @@ void FlannBasedMatcher::read( const FileNode& fn) }; } - if (searchParams == 0) + if (searchParams.empty()) searchParams = new flann::SearchParams(); FileNode sp = fn["searchParams"]; diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index dc6b5fa4db..d173de7dee 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -350,7 +350,7 @@ void SurfFeaturesFinder::find(const Mat &image, ImageFeatures &features) Mat gray_image; CV_Assert(image.type() == CV_8UC3); cvtColor(image, gray_image, CV_BGR2GRAY); - if (surf == 0) + if (surf.empty()) { detector_->detect(gray_image, features.keypoints); extractor_->compute(gray_image, features.keypoints, features.descriptors); diff --git a/modules/video/test/test_backgroundsubtractor_gbh.cpp b/modules/video/test/test_backgroundsubtractor_gbh.cpp index c858e4a093..00d6fb05e6 100644 --- a/modules/video/test/test_backgroundsubtractor_gbh.cpp +++ b/modules/video/test/test_backgroundsubtractor_gbh.cpp @@ -41,7 +41,7 @@ void CV_BackgroundSubtractorTest::run(int) Algorithm::create("BackgroundSubtractor.GMG"); Mat fgmask; - if (fgbg == NULL) + if (fgbg.empty()) CV_Error(CV_StsError,"Failed to create Algorithm\n"); /**