rotem
rotem

Reputation: 19

cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'drawMatches'

I want to make a program that iterates on every single picture in a certain folder, extracts its features, and compares it to the next using ORB, although, I'm facing some issues-

Here is my code:

import numpy as np
import cv2
import os

# img path of images + extension
pth = "/home/oem/Python37/faces/"
ext = ".jpeg"


#init ORB
orb = cv2.ORB_create()

kp_arr = []
des_arr = []

# getting features of all pics
for pic in os.listdir(pth):
    if pic.endswith(ext):

        img = cv2.imread(pth + pic, 0)
        # setting desired img size for all pic in folder
        img = cv2.resize(img, dsize=[460, 460], fx=0.5, fy=0.5)

        kp, des = orb.detectAndCompute(img, None)
        
        kp_arr.append(kp)
        des_arr.append(des)

        cv2.imshow("win", img)
        cv2.waitKey(0)   

for des in des_arr:
    i = 0
    bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
    matches = bf.match(des[i], des[i + 1])
    matches = sorted(matches, key=lambda x:x.distance)

    matching_result = cv2.drawMatches(img, kp, img[i + 1], kp[i + 1], matches, None, 3)

    cv2.imshow("matching result", matching_result)


print("KP ARR: ", kp_arr)
print("DES ARR: ", des_arr)
cv2.destroyAllWindows()

Getting this error when running:

Traceback (most recent call last):
  File "/home/oem/Python37/iterate.py", line 40, in <module>
    matching_result = cv2.drawMatches(img, kp, img[i + 1], kp[i + 1], matches, None, 3)
cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'drawMatches'
> Overload resolution failed:
>  - Can't parse 'keypoints2'. Input argument doesn't provide sequence protocol
>  - Can't parse 'keypoints2'. Input argument doesn't provide sequence protocol
>  - Can't parse 'keypoints2'. Input argument doesn't provide sequence protocol
>  - Can't parse 'keypoints2'. Input argument doesn't provide sequence protocol

Please help, I'm quite new at this..

Upvotes: 1

Views: 2795

Answers (0)

Related Questions