-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
[SOLVED] Public attribute (keypoints) missing from cv2.detail_ImageFeatures() object despite it existing in matchers.hpp #21171
Description
Detailed description
I am not able to access the public attribute of 'keypoints' which is clearly stated in the OpenCV documentation [https://docs.opencv.org/3.4/d4/db5/structcv_1_1detail_1_1ImageFeatures.html#a1defd2a583122cb6360ab12c6333212b], as well as the opencv2/opencv2/stitching/detail/matchers.hpp file. This is sort of a continuation of the inaccessible public attribute of 'descriptors' but I managed to worked around it by producing the object of the same class from the method cv.detail.computeImageFeatures2(finder_algorithm, image). I am one step away from completing my project but it seems to me that the incompletion of this particular class is proving to be a huge hindrance to optimising the sticher class by OpenCV :(
Aim: Obtaining keypoints and descriptors from another algorithm, packing them, and overwriting the attribute values in the class.
I know there is a similar issue #16371, but the owner was trying to find out why the same public attribute 'keypoints' is not working :(
I appreciate all and any help with this. Thank you for you time.
Steps to reproduce
finder = cv.ORB.create()
img = cv.imread('Images/arena_fetch.jpg', 0)
feat = cv.detail.computeImageFeatures2(finder, img)
print(feat)
print(feat.descriptors)
print(feat.keypoints)
Here is the output
<detail_ImageFeatures 0x7f2088ce28a0>
<UMat 0x7f1fefe61870>
Traceback (most recent call last):
File "object_highjack_test.py", line 11, in <module>
print(feat.keypoints)
AttributeError: 'cv2.detail_ImageFeatures' object has no attribute 'keypoints'
Here is code block in matchers.hpp:
struct CV_EXPORTS_W_SIMPLE ImageFeatures
{
CV_PROP_RW int img_idx;
CV_PROP_RW Size img_size;
std::vector<KeyPoint> keypoints;
CV_PROP_RW UMat descriptors;
CV_WRAP std::vector<KeyPoint> getKeypoints() { return keypoints; };
};
Here is the output for dir(feat):
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'descriptors', 'getKeypoints', 'img_idx', 'img_size']
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 - [Not Applicable] I updated to latest OpenCV version and the issue is still there
- [Refer to Issue How to access detail_ImageFeatures.keypoint correctly in python? #16371] There is reproducer code and related data files: videos, images, onnx, etc
UPDATED (Resolved)
We are now able to set and get the keypoints in the class of cv2.detail.ImageFeatures. This will now allow us to utilise various feature finding algorithms such as GeoDesc to be incorporated into the Stitcher class made by OpenCV (similar to Lowe's implementation).
Here is the code block:
finder = cv.ORB.create()
img = cv.imread('Images/arena_fetch.jpg', 0)
feat = cv.detail.computeImageFeatures2(finder, img)
print(feat.descriptors.get())
print(feat.keypoints[0].angle)
print()
finder = cv.SIFT_create()
kps, des = finder.detectAndCompute(img, None)
umat = cv.UMat(des)
feat.descriptors = umat
feat.keypoints = kps
print(feat.descriptors.get())
print(feat.keypoints[0].angle)
Here is the output:
[[ 39 109 230 ... 95 242 212]
[ 34 243 98 ... 30 182 221]
[ 6 4 162 ... 10 49 128]
...
[148 0 75 ... 138 112 128]
[162 48 185 ... 12 85 214]
[ 18 2 6 ... 12 56 4]]
141.79449462890625
[[ 1. 12. 20. ... 23. 13. 9.]
[27. 39. 34. ... 21. 35. 24.]
[ 0. 0. 0. ... 1. 1. 9.]
...
[ 1. 0. 0. ... 18. 4. 5.]
[ 4. 19. 11. ... 0. 6. 19.]
[16. 0. 9. ... 9. 0. 19.]]
27.26062774658203
Here is the output for dir(feat):
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'descriptors', 'getKeypoints', 'img_idx', 'img_size', 'keypoints']