python opencv中的函数cvGetMat中无法识别或不支持的数组类型 [英] Unrecognized or unsupported array type in function cvGetMat in python opencv

查看:107
本文介绍了python opencv中的函数cvGetMat中无法识别或不支持的数组类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在python opencv-2.4.3中进行编码,这给了我如下错误

I am trying to code in python opencv-2.4.3, It is giving me an error as below

Traceback (most recent call last):
 File "/home/OpenCV-2.4.3/cam_try.py", line 6, in <module>
cv2.imshow('video test',im)
 error: /home/OpenCV-2.4.3/modules/core/src/array.cpp:2482: error: (-206)           Unrecognized or unsupported array type in function cvGetMat

我不明白这是什么意思,有人可以帮我吗? 谢谢.

I am not understanding what does that mean, Can anybody help me out? Thankyou.

推荐答案

错误消息的相关代码段为Unrecognized or unsupported array type in function cvGetMat. cvGetMat()函数将数组转换为Mat. Mat是OpenCV在C/C ++领域中使用的矩阵数据类型(注意:您正在使用的Python OpenCV接口使用Numpy数组,然后将它们在后台转换为Mat数组).考虑到这种背景,问题似乎在于您传递给cv2.imshow()的数组im的格式不正确.两个想法:

The relevant snippet of the error message is Unrecognized or unsupported array type in function cvGetMat. The cvGetMat() function converts arrays into a Mat. A Mat is the matrix data type that OpenCV uses in the world of C/C++ (Note: the Python OpenCV interface you are utilizing uses Numpy arrays, which are then converted behind the scenes into Mat arrays). With that background in mind, the problem appears to be that that the array im you're passing to cv2.imshow() is poorly formed. Two ideas:

  1. 这可能是由您的网络摄像头的古怪行为引起的...在某些摄像头上,有时会返回空帧.在将im数组传递给imshow()之前,请尝试确保它不为null.

  1. This could be caused by quirky behavior on your webcam... on some cameras null frames are returned from time to time. Before you pass the im array to imshow(), try ensuring that it is not null.

如果每个 框架上均发生错误,则消除您正在执行的某些处理,并在从网络摄像头抓取框架后立即调用cv2.imshow().如果仍然无法解决问题,那么您会发现网络摄像头存在问题.否则,逐行添加您的处理,直到您找出问题所在为止.例如,从此开始:

If the error occurs on every frame, then eliminate some of the processing that you are doing and call cv2.imshow() immediately after you grab the frame from the webcam. If that still doesn't work, then you'll know it's a problem with your webcam. Else, add back your processing line by line until you isolate the problem. For example, start with this:

while True:
    # Grab frame from webcam
    retVal, image = capture.read(); # note: ignore retVal

#   faces = cascade.detectMultiScale(image, scaleFactor=1.2, minNeighbors=2, minSize=(100,100),flags=cv.CV_HAAR_DO_CANNY_PRUNING);

    # Draw rectangles on image, and then show it
#   for (x,y,w,h) in faces:
#       cv2.rectangle(image, (x,y), (x+w,y+h), 255)
    cv2.imshow("Video", image)

    i += 1;

来源:相关问题:OpenCV C ++ Video Capture不支持似乎有效

这篇关于python opencv中的函数cvGetMat中无法识别或不支持的数组类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆