0

I'm trying to extract features form image for checking similarities using CV2 from couple of days and stuck in this problem. Have try a-lot of solution but not get resolve error. My version of CV2:

<module 'cv2.cv2' from '/home/mobin/anaconda3/lib/python3.7/site-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so'>

4.1.2

My code:

import cv2
import matplotlib.pyplot as plt
print(cv2)
print(cv2.__version__)
original = cv2.imread("/home/mobin/Merging and Visualization of 7-JSON/group_by_rule_test/black_cotton_sweatshirt/0/1-black_cotton_sweatshirt.jpg")
cv2.imshow("original", original)
image_to_compare = cv2.imread("/home/mobin/Merging and Visualization of 7-JSON/group_by_rule_test/black_cotton_sweatshirt/0/2-black_cotton_sweatshirt.jpg")
print('ok here')
# 2) Check for similarities between the 2 images
sift = cv2.xfeatures2d.SIFT_create()

print('ok here1')
kp_1, desc_1 = sift.detectAndCompute(original, None)
kp_2, desc_2 = sift.detectAndCompute(image_to_compare, None)
print('ok here2')

index_params = dict(algorithm=0, trees=5)
search_params = dict()
flann = cv2.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(desc_1, desc_2, k=2)
print('ok here3')

good_points = []
ratio = 0.6
for m, n in matches:
    if m.distance < ratio*n.distance:
        good_points.append(m)
        print(len(good_points))



cv2.imshow("result", result)
cv2.imshow("Original", original)
cv2.imshow("Duplicate", image_to_compare)
cv2.waitKey(0)
cv2.destroyAllWindows()

Every time i run this script it show me error:

Traceback (most recent call last):
  File "run_test.py", line 9, in <module>
    sift = cv2.xfeatures2d.SIFT_create()
AttributeError: module 'cv2.cv2' has no attribute 'xfeatures2d'

Some times:

Traceback (most recent call last):
  File "run_test.py", line 6, in <module>
    cv2.imshow("original", original)
cv2.error: OpenCV(4.1.2) /io/opencv/modules/highgui/src/window.cpp:651: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'
Mobin Al Hassan
  • 954
  • 11
  • 22
  • please do a minimum web search befor you post your problems on StackOverflow. The post linked above was the first google hit for "cv2.xfeatures2d" – Piglet Dec 15 '19 at 07:22
  • I have search many time with different queries (as i have mention in you Question) the link that you attach did not solve my problem that's i'm asking again.. – Mobin Al Hassan Dec 16 '19 at 06:41
  • that's why you should present what you have tried so far. how should I know what you have tried. it's the same error. your problem is that you don't have xfeatures2d so the obvious solution is to use an OpenCV build that has it. why does that not work for you? – Piglet Dec 16 '19 at 07:15
  • now some things work if i run myScript form terminal using `python my_script.py` its work but not working in notebook Jupiter – Mobin Al Hassan Dec 16 '19 at 07:36

0 Answers0