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.

1
  • Does the error immediately after you start the webcam program? Or does it occur after a few frames have been successfully returned? Commented Jan 4, 2013 at 15:05

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

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks A lot, I was eagerly waiting for your reply.Yes it have some problem in cv2.imshow.And when i try to print image, it is None.IS it the problem of webcam? But it works fine for my simple video capture code of old version. When i try individually printing, it shows >>> capture <VideoCapture 0x2c949d0> >>> cascade >>> print image <None>. What should I Do??
where are you printing the image? If it is None right after capture.read(), then check the retVal variable which may contain an error code. Else tell me where you're printing it.
I am using python Idle as editor and when i print it gives as none and retVal as False.
If you are printing retVal and image right after you call capture.read(), then it sounds like you have a problem with your webcam. The documentation says retVal is False when "no frames have been grabbed (such as when a camera has been disconnected, or there are no more frames in video file)." Does your camera work in other cv2 v2.4.3 scripts?
I have reinstalled ubuntu 11.10 on my desktop and installing opencv-2.4.3, And want to restart again so that I will sure that am not missing any opencv library. Is it a right decision to install opencv-2.4.3, I am new to processing, sorry for silly questions but you are using 2.4.3 so just want to ask, does it cause any problem while installing and processimg?
|
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.

Comments

1

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

Comments

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.

Comments

0

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

Comments

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

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.