python opencv中函数cvGetMat中无法识别或不支持的数组类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14155081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unrecognized or unsupported array type in function cvGetMat in python opencv
提问by shreya
I am trying to code in python opencv-2.4.3, It is giving me an error as below
我正在尝试在 python opencv-2.4.3 中编码,它给了我如下错误
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.
我不明白这是什么意思,有人可以帮我吗?谢谢你。
采纳答案by Brandon Hymanson
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 Matis 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 Matarrays). With that background in mind, the problem appears to be that that the array imyou're passing to cv2.imshow()is poorly formed. Two ideas:
错误消息的相关片段是Unrecognized or unsupported array type in function cvGetMat. 该cvGetMat()函数将数组转换为Mat. AMat是 OpenCV 在 C/C++ 世界中使用的矩阵数据类型(注意:您正在使用的 Python OpenCV 接口使用 Numpy 数组,然后在幕后将其转换为Mat数组)。考虑到这一背景,问题似乎是im您传递给的数组cv2.imshow()格式不正确。两个想法:
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
imarray toimshow(), try ensuring that it is not null.If the error occurs on everyframe, 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;
这可能是由网络摄像头上的古怪行为引起的……在某些摄像头上,不时返回空帧。在将
im数组传递给 之前imshow(),请尝试确保它不为空。如果错误发生在每一帧上,则消除您正在执行的一些处理,并
cv2.imshow()在从网络摄像头抓取帧后立即调用。如果这仍然不起作用,那么您就会知道这是网络摄像头的问题。否则,逐行添加您的处理,直到您隔离问题。例如,从这个开始: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;
source: Related Question: OpenCV C++ Video Capture does not seem to work
回答by Gab Hum
I am working in Windows with Opencv 2.3.1 and Python 2.7.2, so, I had the same problem, I solved it pasting the following DLL files: opencv_ffmpeg.dll and opencv_ffmpeg_64.dll in the installation folder of Python. Maybe it help you with a similar solution in Ubuntu.
我在使用 Opencv 2.3.1 和 Python 2.7.2 的 Windows 中工作,所以,我遇到了同样的问题,我解决了它,在 Python 的安装文件夹中粘贴了以下 DLL 文件:opencv_ffmpeg.dll 和 opencv_ffmpeg_64.dll。也许它可以帮助您在 Ubuntu 中使用类似的解决方案。
回答by Russj
For me, like Gab Hum did, I copied opencv_ffmpeg245.dll to my python code folder. Then it works.
对我来说,就像 Gab Hum 所做的那样,我将 opencv_ffmpeg245.dll 复制到了我的 python 代码文件夹中。然后它起作用了。
回答by user2737945
I was having the same error, and after about an hour of searching for the error, I found the path to the image to be improperly defined. It solved my problem, may be it will solve yours.
我遇到了同样的错误,在搜索错误大约一个小时后,我发现图像的路径定义不正确。它解决了我的问题,也许它会解决你的问题。
回答by k1ngarthur
I solved the porblem by using a BGR-picture. the one from my cam was YUYV by default!
我通过使用 BGR-picture 解决了这个问题。默认情况下,我的摄像头中的那个是 YUYV!
回答by Mohanavel T
Check your Image Array (or NpArray),(by printing it) whether you are trying to pass an array of images at one shot instead of passing each image at once.
检查您的图像阵列(或 NpArray),(通过打印它)您是否试图一次传递一组图像而不是一次传递每个图像。
A single image array would look like :
单个图像数组如下所示:
[[[ 76 85 103] ... [ 76 85 103]], ... ]
[[[76 85 103] ... [ 76 85 103]], ... ]
Rows encloses each columns, each matrix(pixes) encloses no of rows, each image comprises of matrices (pixels).
行包含每一列,每个矩阵(像素)不包含行,每个图像由矩阵(像素)组成。

