How to solve "cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'imshow'"

0

Issue

I’m learning how to use opencv, but I’m running into this problem.

from cvzone.HandTrackingModule import HandDetector
import cv2


cap = cv2.VideoCapture("https://192.168.178.49:8080/video")
detector = HandDetector(maxHands=1, detectionCon=0.7)

while True:
    success, img= cap.read()
    
    img = detector.findHands(img) 
    
    cv2.imshow("AI", img)
    cv2.waitKey(1)

Results in this error:

INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
  File "d:\Programming\Arm Code\testhandai.py", line 13, in <module>
    cv2.imshow("AI", img)
cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
>  - mat is not a numerical tuple
>  - Expected Ptr<cv::cuda::GpuMat> for argument 'mat'
>  - Expected Ptr<cv::UMat> for argument 'mat'

I’m using Python 3.8 64-bit and the latest version for all the packages.
Thank you.

Solution

Output of detector.findHands(img) is a tuple. You should give second element of it as input to cv2.imshow():

from cvzone.HandTrackingModule import HandDetector
import cv2


cap = cv2.VideoCapture("https://192.168.178.49:8080/video")
detector = HandDetector(maxHands=1, detectionCon=0.7)

while True:
    success, img= cap.read()
    
    img = detector.findHands(img) 
    
    cv2.imshow("AI", img[1])
    cv2.waitKey(1)

Answered By – Mohammad Khoshbin

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave A Reply

Your email address will not be published.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More