添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
讲道义的鞭炮  ·  【OpenCV 例程200篇】60. ...·  15 小时前    · 
想出国的洋葱  ·  Extracting MICR in ...·  21 小时前    · 
玩命的水桶  ·  (-215:Assertion ...·  21 小时前    · 
风流的手术刀  ·  解决error C1083: ...·  昨天    · 
有爱心的米饭  ·  How To Access BT Hub ...·  5 月前    · 
坏坏的红茶  ·  MySQL Workbench生成ER图 ...·  6 月前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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.

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)

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)
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.