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