I want to make a simple project about logo detecting. So I tried to follow OpenCV-Python tutorial about feature detection. OpenCV: Feature Matching
I wrote my code like below.
ratio = 0.8
logo = cv.imread("T01/CocaCola_logo2.png", cv.IMREAD_GRAYSCALE)
img = cv.imread("T01/CocaCola.png", cv.IMREAD_GRAYSCALE)
orb = cv.ORB_create()
kp_logo, des_logo = orb.detectAndCompute(logo, None)
kp_img, des_img = orb.detectAndCompute(img, None)
FLANN_INDEX_LSH = 6
index_params = dict(algorithm=FLANN_INDEX_LSH,
table_number=6,
key_size=12,
multi_probe_level=1)
search_params = dict(checks=50)
flann = cv.FlannBasedMatcher(index_params, search_params)
match_flann = flann.knnMatch(des_logo, des_img, k=2)
good = []
for p, q in match_flann:
if p.distance > q.distance*ratio:
good.append(p)
try:
img_match = np.empty((max(logo.shape[0], img.shape[0]), logo.shape[1] + img.shape[1], 3), dtype=np.uint8)
cv.drawMatchesKnn(logo, kp_logo, img, kp_img, good,
outImg=img_match, matchColor=None, singlePointColor=(255, 255, 255), flags=2)
cv.imshow("flann matching", img_match)
cv.waitKey(0)
except:
print("...")
This code does not work properly. Process always got handled by error with drawMatchesKnn(). Before I add try-except to that function, process made a system error : SystemError: returned NULL without setting an error
What is the cause of the problem? I tried to search for a long time but it's not easy to me.
stack trace : Traceback (most recent call last): File "C:/Users/choib/Desktop/openCVtest3/T01_ORBtest.py", line 73, in cv.drawMatchesKnn(logo, kp_logo, img, kp_img, good, outImg=img_match, matchColor=None, singlePointColor=(255, 255, 255), flags=2) SystemError: returned NULL without setting an error
img_match = cv.drawMatchesKnn(logo, kp_logo, img, kp_img, good, flags=2)does it give you also error? - api55img_match = cv.drawMatchesKnn(logo, kp_logo, img, kp_img, good, outImg=None, flags=2)(if outImg is not mentioned, it cause type error.) But it has same error as I wrote in question. - HS. Choi