[Stitching_detailed.cpp] Matcher as cv::Ptr discussion thread.

asked 2016-10-26 03:56:43 -0600

DaePa gravatar image

updated 2016-10-26 15:05:00 -0600

Hello everyone,

I encountered a thing while fiddling around with the stitching_detailed.cpp tutorial provided on source repository. Before proceeding please note that I had to improvise myself a C++ developer expert, I hope not to be trivial on my considerations.

In the tutorial, get straight to the point where the cv::FeaturesMatcher is defined.

On Eclipse C++ IDE, with fully set up project, the following will not compile (g++):

One can define the matcher in two different ways, one being

Ptr<FeaturesMatcher> matcher;
matcher = makePtr<BestOf2NearestMatcher>(try_cuda, match_conf);
(*matcher)(features, pairwise_matches);

The issue is on line 3, where we call the matcher as a pointer. When that happens, a conflicting declaration appears to occur within matcher and pairwise_matches.

On the other hand, the following will compile just fine:

And the other, more direct, being

BestOf2NearestMatcher matcher(tryCuda,matchingConfidence);
matcher(features, pairwiseMatches);
matcher.collectGarbage();

Question: why would I need to instantiate a matcher as a pointer when it works perfectly fine otherwise?

I wouldn't bother that much myself about it, but here is another (less trivial?) question. The following code works just fine:

cv::Ptr<cv::detail::FeaturesFinder> finder;
finder = cv::makePtr<cv::detail::SurfFeaturesFinder>();
for(int currentImage=0;currentImage<imagesCount;currentImage++) {
   (*finder)(images[currentImage],features[currentImage]);
}

For sake of readability, one would expect that a similar construction is going to work even with the matcher, not only with the finder. But this is not the case. Aside question: would it be a waste of time to annotate the tutorial to explain why things have to work this way?

Thank you for your time.

edit retag flag offensive close merge delete

Comments

cv::Ptr is not just a 'normal' pointer. It is a smart pointer and you cannot treat it as a normal pointer. It also has some advantages over a normal pointer. Read the docs for that: cv::Ptr

boaz001 gravatar imageboaz001 ( 2016-10-26 07:25:54 -0600 )edit

Yes, I've got that figured out. However, my question is not about the cv::Ptr. Instead, it is about why the Ptr pointer call fails with a little (and somehow innocent) edit to the tutorial (stitching_detailed). Is the pointer needed because a loop cycle is following && one must call the pointed object inside the loop?

DaePa gravatar imageDaePa ( 2016-10-26 10:22:45 -0600 )edit

@DaePa, can you add the error msg you get, when using a cv::Ptr ?

(also, compiler/os/opencv version, please)

berak gravatar imageberak ( 2016-10-26 10:26:23 -0600 )edit

@berak something really strange is happening. This evening, when I was working on the code, I got a bunch of errors. I commented out the not working section of the code and wrote the working one. Now, switching comments, the error is not showing up anymore. I don't know what to say. Please notice that I first had the error two days ago.

I have edited my original question to reflect this.

compiler is g++ opencv 3.1 Ubuntu 16.04 LTS

DaePa gravatar imageDaePa ( 2016-10-26 15:00:37 -0600 )edit