Twisted Soul
Twisted Soul

Reputation: 1

typeerror argument 'image' must be iplimage

I am new at opencv. While compiling python code, I am getting the following error.

TypeError: argument 'image' must be iplimage

Please explain what iplimage is and why I am getting this.

Here is my code:

import cv
capture=cv.CaptureFromCAM(0)
image=cv.QueryFrame(capture)
writer=cv.CreateVideoWriter("output.avi", 0, 15,(800,600) , 1)
count=0
cv.NamedWindow('Image_Window')
while count<250:
    image=cv.QueryFrame(capture)
    cv.WriteFrame(writer, image)
    cv.ShowImage('Image_Window',image)
    cv.WaitKey(2)
    count+=1

Thanks.

Upvotes: 0

Views: 1626

Answers (2)

hjweide
hjweide

Reputation: 12523

You are not providing a valid codec to the video writer. I tried your code and got an error, and then I changed the codec being used and it worked.

You should change this line:

writer=cv.CreateVideoWriter("output.avi", 0, 15,(800,600) , 1)

to this:

writer=cv.CreateVideoWriter("output.avi", cv.CV_FOURCC('i','Y', 'U', 'V'), 15,(800,600) , 1) 

However Andrey Kamaev is correct in saying that you should rather not be using the cv interface, the newer cv2 interface is both easier and more reliable. In this question I covered how to write image frames to a file using the cv2 interface.

If the above mentioned codec does not work for you, I am afraid you might be in for some trouble. You may refer to this question to learn more about finding a valid codec.

Upvotes: 1

IplImage is the basic image class in OpenCV. cv.QueryFrame should return an IplImage. But it seems, it doesn't in your case.

You should try to check against NULL. QueryFrame returns NULL instead of an image in case of an error.

Also, check out THIS question. You might find your answer here.

Upvotes: 1

Related Questions