7

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.

4

7 回答 7

6

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

于 2013-01-04T15:10:52.477 回答
4

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.

于 2013-09-01T19:12:45.887 回答
1

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

于 2013-10-10T17:22:38.063 回答
0

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.

于 2013-01-15T17:15:46.937 回答
0

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

于 2013-04-19T04:16:20.507 回答
0

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.

A single image array would look like :

[[[ 76 85 103] ... [ 76 85 103]], ... ]

Rows encloses each columns, each matrix(pixes) encloses no of rows, each image comprises of matrices (pixels).

于 2019-02-04T07:44:41.640 回答
0

It is always good to have a sanity check, to be sure your camera is working. In my case my camera is

raspistill -o test.jpg

于 2021-07-21T09:58:09.177 回答