Unrecognized or unsupported array type in function cvGetMat in python opencv

匿名 (未验证) 提交于 2019-12-03 01:57:01

问题:

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  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.

回答1:

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. 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.

  2. 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; 

source: Related Question: OpenCV C++ Video Capture does not seem to work



回答2:

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.



回答3:

I solved the porblem by using a BGR-picture. the one from my cam was YUYV by default!



回答4:

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.



回答5:

For me, like Gab Hum did, I copied opencv_ffmpeg245.dll to my python code folder. Then it works.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!