如何解决"cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'imshow'"



我正在学习如何使用opencv,但我遇到了这个问题。

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)

导致此错误的结果:

INFO: Created TensorFlow Lite XNNPACK delegate for CPU.
Traceback (most recent call last):
File "d:ProgrammingArm Codetesthandai.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'

我使用的是Python 3.8 64位和所有软件包的最新版本。非常感谢。

detector.findHands(img)的输出是一个元组。您应该将它的第二个元素作为输入提供给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)

mediapipe添加了一个新变量,该变量破坏了手动跟踪和姿态估计调用的复杂性和模型复杂性。请参见下文。

现在我在做人脸检测,这个模块工作得很好,但当我把它拉到另一个模块时,它就失败了。

用于手动跟踪模块

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, )

用于估计后模块:

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)

只需进入源代码编辑器和

pip uninstall opencv-python

然后重新安装

pip install opencv-python

我有同样的错误,这对我有效

最新更新