5

I am really beginning for python. I download project from the internet. But when I try to run I got these errors. I think my install module is not supported for the project. How to fix this issue?

Error

Traceback (most recent call last): File "compare.py", line 20, in sift = cv2.xfeatures2d.SIFT_create() cv2.error: OpenCV(4.2.0) /Users/travis/build/skvark/opencv-python/opencv_contrib/modules/xfeatures2d/src/sift.cpp:1210: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'

Full code

import cv2
import numpy as np

original = cv2.imread("images/original_golden_bridge.jpg")
image_to_compare = cv2.imread("images/george-washington-bridge.jpg")

# 1) Check if 2 images are equals
if original.shape == image_to_compare.shape:
    print("The images have same size and channels")
    difference = cv2.subtract(original, image_to_compare)
    b, g, r = cv2.split(difference)

    if cv2.countNonZero(b) == 0 and cv2.countNonZero(g) == 0 and cv2.countNonZero(r) == 0:
        print("The images are completely Equal")
    else:
        print("The images are NOT equal")

# 2) Check for similarities between the 2 images

sift = cv2.xfeatures2d.SIFT_create()
kp_1, desc_1 = sift.detectAndCompute(original, None)
kp_2, desc_2 = sift.detectAndCompute(image_to_compare, None)

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)

good_points = []
ratio = 0.6
for m, n in matches:
    if m.distance < ratio*n.distance:
        good_points.append(m)
print(len(good_points))
result = cv2.drawMatches(original, kp_1, image_to_compare, kp_2, good_points, None)

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

python versions

python --version Python 3.8.1

python2 --version Python 2.7.16

module versions

pip3 freeze
certifi==2019.11.28
numpy==1.18.1
opencv-contrib-python==4.2.0.32
opencv-python==4.2.0.32

I followed this tutorial

And also I followed this answer https://stackoverflow.com/a/52514095/8822337

Traceback (most recent call last): File "compare.py", line 1, in import cv2 ModuleNotFoundError: No module named 'cv2'

I uninstall pip3 opencv modules and installed these two.

pip install opencv-python==3.4.2.16
pip install opencv-contrib-python==3.4.2.16
FBruzzesi
  • 5,942
  • 3
  • 14
  • 35
BIS Tech
  • 12,833
  • 7
  • 71
  • 107
  • 1
    See https://docs.opencv.org/4.1.1/d2/dca/group__xfeatures2d__nonfree.html – fmw42 Feb 10 '20 at 20:43
  • @fmw42 so, what do I do now? I want to just run the code. – BIS Tech Feb 11 '20 at 02:40
  • @nathancy I unistall my privious module and I added these two...Now I run the code (`python compare.py`)..but new error File "compare.py", line 1, in import cv2 ModuleNotFoundError: No module named 'cv2' – BIS Tech Feb 11 '20 at 02:41
  • previously I used pip3 module, now I used pip module.. – BIS Tech Feb 11 '20 at 02:46
  • @nathancy How to fix this issue? – BIS Tech Feb 11 '20 at 02:46
  • Stick with one Python installation, if you use python3 then use pip3 to install the modules – nathancy Feb 11 '20 at 02:48
  • pip3 cannot install these two versionsas... Error ERROR: Could not find a version that satisfies the requirement opencv-contrib-python==3.4.2.16 (from versions: 3.4.8.29, 3.4.9.31, 4.1.2.30, 4.2.0.32) ERROR: No matching distribution found for opencv-contrib-python==3.4.2.16 – BIS Tech Feb 11 '20 at 02:50
  • Is it possible to remove python3? – BIS Tech Feb 11 '20 at 02:50
  • Does this answer your question? [sift = cv2.xfeatures2d.SIFT\_create() not working even though have contrib installed](https://stackoverflow.com/questions/52305578/sift-cv2-xfeatures2d-sift-create-not-working-even-though-have-contrib-instal) – HansHirse Feb 11 '20 at 05:29
  • no, I already did this.you can saw in above comments.. I got this error message..Traceback (most recent call last): File "compare.py", line 1, in import cv2 ModuleNotFoundError: No module named 'cv2' – BIS Tech Feb 11 '20 at 05:33
  • @HansHirse please reopen my question – BIS Tech Feb 11 '20 at 05:34
  • 1
    worked for me,try these .. pip install opencv-python==3.4.2.17 , pip install opencv-contrib-python==3.4.2.17 – Aravinda_gn Dec 04 '20 at 10:09

0 Answers0