Ask Your Question
0

DMatch: no member "distance" (OpenCV3)

asked 2014-10-24 08:51:23 -0600

Doombot gravatar image

updated 2014-10-24 09:40:33 -0600

So, it seems there is no longer a "distance" member in

std::vector<std::vector<cv::DMatch>> matches;

When looking at the definition of DMatch in "types.hpp":

class CV_EXPORTS_W_SIMPLE DMatch
{
public:
    CV_WRAP DMatch();
    CV_WRAP DMatch(int _queryIdx, int _trainIdx, float _distance);
    CV_WRAP DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance);

    CV_PROP_RW int queryIdx; // query descriptor index
    CV_PROP_RW int trainIdx; // train descriptor index
    CV_PROP_RW int imgIdx;   // train image index

    CV_PROP_RW float distance;

    // less is better
    bool operator<(const DMatch &m) const;
};

/*!
  traits
*/
template<> class DataType<DMatch>
{
public:
    typedef DMatch      value_type;
    typedef int         work_type;
    typedef int         channel_type;

    enum { generic_type = 0,
           depth        = DataType<channel_type>::depth,
           channels     = (int)(sizeof(value_type)/sizeof(channel_type)), // 4
           fmt          = DataType<channel_type>::fmt + ((channels - 1) << 8),
           type         = CV_MAKETYPE(depth, channels)
         };

    typedef Vec<channel_type, channels> vec_type;
};

I am doing FLANN matching. At some point, after computing the matches, an error appears:

std::vector<std::vector<cv::DMatch>> matches;

// ... Some code //

//-- Quick calculation of max and min distances between keypoints
    for( int i = 0; i < objectDescriptors.rows; i++ )
    { 
        double dist = matches[i].distance;
        if( dist < min_dist ) min_dist = dist;
        if( dist > max_dist ) max_dist = dist;
    }

Error message on "distance" : Error: class "std::vector<cv::dmatch,std::allocator<cv::dmatch>>" has no member "distance".

Which is kind of NOT true when you look at the definition.

Similarly, when using this:

std::vector<cv::DMatch> good_matches;

for( int i = 0; i < objectDescriptors.rows; i++ )
{ 
    if( matches[i].distance <= max(2*min_dist, 0.02) ) {
    good_matches.push_back( matches[i]); 
    }
}

gets the same error for "distance" and then add that the .push_back is: " no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=cv::DMatch, _Alloc=std::allocator<cv::dmatch>]" matches the argument list argument types are: (std::vector<cv::dmatch, std::allocator<cv::dmatch="">>) object type is: std::vector<cv::dmatch, std::allocator<cv::dmatch="">>

Which might be related.

Has anyone found some way to get around this?

edit retag flag offensive close merge delete

Comments

did you mean: "Which is kind of not true when you look at the definition." ?

also, exact error msg needed.

berak gravatar imageberak ( 2014-10-24 09:19:59 -0600 )edit

Err yes a mistake of mine! Updating the error message

Doombot gravatar imageDoombot ( 2014-10-24 09:30:28 -0600 )edit

There is no member called Distance, but there is one called distance.

boaz001 gravatar imageboaz001 ( 2014-10-24 09:34:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-10-24 09:48:41 -0600

berak gravatar image

this time, it's not opencv's fault, hehe ;)

std::vector<std::vector<cv::DMatch>> matches;

this is a 2d vector, which is wrong, it should be a single one, like this:

std::vector<cv::DMatch> matches;

(so, in your current code, matches[i] is another vector<DMatch>, not the DMatch item itself [with the required distance member] )

edit flag offensive delete link more

Comments

1

Oh! I really prefer when it is my fault, easier to correct... I guess I just followed a (third party) tutorial without understanding correctly each elements! It compiles now, and the only error showing on execution is that the retrieved distance is -9.2559631349317831e+061 (:O) which I will work on! :D

Doombot gravatar imageDoombot ( 2014-10-24 10:07:43 -0600 )edit

Question Tools

Stats

Asked: 2014-10-24 08:51:23 -0600

Seen: 1,141 times

Last updated: Oct 24 '14