Skip to content

cv2.detail_MatchesInfo() object does not contain public attributes (matches and inliers_mask) despite existing in matchers.hpp #21364

@oguzhanguclu

Description

@oguzhanguclu
System information (version)
  • OpenCV => 4.5.5
  • Operating System / Platform => MacOS 11
Detailed description

The matches and inliers_mask attributes of the cv2.detail_MatchesInfo() class could not be accessed from python interface, despite they are publicly available in the matchers.hpp source file (https://github.com/opencv/opencv/blob/4.x/modules/stitching/include/opencv2/stitching/detail/matchers.hpp).
Therefore, developers are not able to make any changes on the computed matches from the cv2.detail_MatchesInfo() object. (The getMatches() method of the class allows to acquire matches but developers might need to handle and make changes on matches)

A very similar issue #21171 for the cv2.detail_ImageFeatures() class was solved and the merged in the latest release (OpenCV 4.5.5).

Steps to reproduce
finder = cv.ORB.create()
image1 = cv.imread('image1.jpg', cv.IMREAD_GRAYSCALE)
image2 = cv.imread('image2.jpg', cv.IMREAD_GRAYSCALE)

img_feat1 = cv.detail.computeImageFeatures2(finder, image1)
img_feat2 = cv.detail.computeImageFeatures2(finder, image2)

matcher = cv.detail.BestOf2NearestMatcher_create()
matches_info = matcher.apply(img_feat1, img_feat2)

print(matches_info.matches)
The output is
Traceback (most recent call last):
  File "/matches_info_test.py", line 17, in <module>
    print(matches_info.matches)
AttributeError: 'cv2.detail_MatchesInfo' object has no attribute 'matches'
The output of dir(matches_info):
['H', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'confidence', 'dst_img_idx', 'getInliers', 'getMatches', 'num_inliers', 'src_img_idx']
The related code block in matchers.hpp:
struct CV_EXPORTS_W_SIMPLE MatchesInfo
{
    MatchesInfo();
    MatchesInfo(const MatchesInfo &other);
    MatchesInfo& operator =(const MatchesInfo &other);

    CV_PROP_RW int src_img_idx;
    CV_PROP_RW int dst_img_idx;       //!< Images indices (optional)
    std::vector<DMatch> matches;
    std::vector<uchar> inliers_mask;    //!< Geometrically consistent matches mask
    CV_PROP_RW int num_inliers;                    //!< Number of geometrically consistent matches
    CV_PROP_RW Mat H;                              //!< Estimated transformation
    CV_PROP_RW double confidence;                  //!< Confidence two images are from the same panorama
    CV_WRAP std::vector<DMatch> getMatches() { return matches; };
    CV_WRAP std::vector<uchar> getInliers() { return inliers_mask; };
};

Adding CV_PROP_RW keyword to the related two lines would solve the issue and make lots of things easier for the developers.

Issue submission checklist
  • [Yes] I report the issue, it's not a question
  • [Yes] I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • [Yes] I updated to latest OpenCV version and the issue is still there
  • [Yes] There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions