cv2.error: OpenCV(4.8.1) :-1: error: (-5:Bad argument)in function 'cvtColor'

534 views Asked by At
import cv2
import numpy as np
from cvzone import HandTrackingModule as htm
import time
import autopy

wCam, hCam = 640, 480

cap = cv2.VideoCapture(0)
cap.set(3,wCam)
cap.set(4,hCam)
pTime = 0
detector = htm.HandDetector(maxHands=1)

while True:
    success, img = cap.read()
    if not success:
        print("Failed to capture a frame from the webcam.")
        break

    img = detector.findHands(img)
    lmList, bbox = detector.findHands(img)

    cTime = time.time()
    fps = 1/(cTime-pTime)
    pTime = cTime
    cv2.putText(img, str(int(fps)), (20, 50), cv2.FONT_HERSHEY_PLAIN, 3, (255,0,0), 3)

    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    cv2.imshow("Image", img)
    cv2.waitKey(1)

Running it gives the following error output: D:\GestureAI\venv\Scripts\python.exe D:\GestureAI\AIVirtualMouse.py INFO: Created TensorFlow Lite XNNPACK delegate for CPU. Traceback (most recent call last): File "D:\GestureAI\AIVirtualMouse.py", line 22, in lmList, bbox = detector.findHands(img) File "D:\GestureAI\venv\lib\site-packages\cvzone\HandTrackingModule.py", line 54, in findHands imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) cv2.error: OpenCV(4.8.1) :-1: error: (-5:Bad argument) in function 'cvtColor'

Overload resolution failed:

  • src is not a numerical tuple
  • Expected Ptr<cv::UMat> for argument 'src'

Process finished with exit code 1

I was expecting that camera view will open with hand detection lines enabled in it

0

There are 0 answers