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

We Are Going To Discuss About How to solve “cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function ‘imshow'”. So lets Start this Python Article.

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

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

    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)

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

    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)

Solution 1

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)

Original Author Mohammad Khoshbin Of This Content

Solution 2

mediapipe added a new variable, which screw up the handtracking and pose estimation call complexity and model_complexity. See below.

Now Im working on the face detection, and the module work perfect, but when I pull it into a different it fails.

for handtracking module

def __init__(self, mode=False, maxHands=2, complexity = 1, detectionCon=0.5, trackCon=0.5):
    self.mode = mode
    self.maxHands = maxHands
    self.complexity = complexity
    self.detectionCon = detectionCon
    self.trackCon = trackCon
    self.mpHands = mp.solutions.hands
    self.hands = self.mpHands.Hands(self.mode, self.maxHands, self.complexity,
                                    self.detectionCon, self.trackCon, )

for the post esitimation module:

def __init__(self, mode = False, model_complexity = 1, smooth = True,
                    enable_segmentation = False, smooth_segmentation = True, min_detection_confidence = 0.5,
                    min_tracking_confidence = 0.5):
    self.mode = mode
    self.model_complexity = model_complexity
    self.smooth = smooth
    self.enable_segmentation = enable_segmentation
    self.smooth_segmentation = smooth_segmentation
    self.detectionCon = min_detection_confidence
    self.trackCon = min_tracking_confidence
    self.mpDraw = mp.solutions.drawing_utils
    self.mpPose = mp.solutions.pose
    self.pose = self.mpPose.Pose(self.mode, self.model_complexity, self.smooth, self.enable_segmentation,
                                 self.detectionCon, self.trackCon)

Original Author William JOhnson Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment