Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

DMatch: no member "distance" (OpenCV3)

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:

double dist = matches[i].distance; //Distance is underlined, class has no member "Distance"

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

Has anyone found some way to get around this?

click to hide/show revision 2
NOT true, error message

DMatch: no member "distance" (OpenCV3)

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; //Distance is underlined, 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" "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 the 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?

DMatch: no member "distance" (OpenCV3)

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 the 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?