Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognized or unsupported array type in function cvGetMat in python opencv

Tags:

python

opencv

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.

like image 527
shreya Avatar asked Jan 04 '13 10:01

shreya


3 Answers

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

like image 80
Brandon Jackson Avatar answered Nov 10 '22 05:11

Brandon Jackson


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.

like image 36
user2737945 Avatar answered Nov 10 '22 05:11

user2737945


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

like image 1
k1ngarthur Avatar answered Nov 10 '22 07:11

k1ngarthur