开发者

Problem saving AVI file in python 2.6 using OpenCV 2.1

开发者 https://www.devze.com 2023-02-14 23:12 出处:网络
I am an amateur computer programmer who has been noodling around with programming for ages. I have little formal training; so please forgive inefficiencies in the code included below.

I am an amateur computer programmer who has been noodling around with programming for ages. I have little formal training; so please forgive inefficiencies in the code included below.

I have been working on a motion tracking algorithm in Python 2.6 using OpenCV 2.1. I am running everything on a Dell laptop running windows XP SP2. I have an unusual situation. I had several AVI input and output codes working fine a couple of months ago. I do not remember changing anything on my computer in the interim (although this must not be true). Now I get an error when the code tries to release the video writer construct.

The code below is used to generate a movie with moving circles on different sizes. I used these movies to test my motion tracking code. When I run it now, it fails to save the movie at the end of the file. Here is the code.

 Created on Apr 30, 2010

 @author: Josh
 '''
 #!/usr/bin/env python

 from opencv.cv import *  
 from opencv.highgui import *  

 if __name__ == '__main__':
     width = 640
     height = 480
     cvNamedWindow("Test Image", CV_WINDOW_AUTOSIZE);
     movie = cvCreateVideoWriter('C:\\Documents and Settings\\Josh\\Desktop\\Microcirc    working\\South.avi', CV_FOURCC('d','i','v','x'),24, cvSize(width,height),0)
     frame = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
     for m in range(0,5):
         n = m
         l = m
         for i in range(0,height):
             for j in range(0,width):
     #            i = int(array)
     #            j = int(element)
                 cvSet2D(frame, i, j, 255)

       开发者_高级运维  xcenter = width/2
         ycenter = height/2
         print n
         cvCircle(frame, cvPoint(xcenter+l,ycenter+n), 10, 0, -1)
         cvCircle(frame, cvPoint(xcenter+l,ycenter+n-60), 10, 0, -1)
         cvCircle(frame, cvPoint(xcenter+l,ycenter+n+60), 10, 0, -1)
         cvCircle(frame, cvPoint(xcenter+l+60,ycenter+n), 20, 0, -1)
         cvCircle(frame, cvPoint(xcenter-l+60,ycenter-n-60), 20, 0, -1)
         cvCircle(frame, cvPoint(xcenter+l+60,ycenter+n+60), 20, 0, -1)
         cvCircle(frame, cvPoint(xcenter+l-60,ycenter+n), 3, 0, -1)
         cvCircle(frame, cvPoint(xcenter+l-60,ycenter+n-60), 3, 0, -1)        
         cvCircle(frame, cvPoint(xcenter+l-60,ycenter+n+60), 3, 0, -1)

         cvShowImage("Test Image", frame)

         char = cvWaitKey(3)
         cvWriteFrame(movie, frame)

     print 'out of for loop'
     cvReleaseVideoWriter(movie)
     print 'writer released'

When I run the code, I get the following response from the computer.

 0
 1
 2
 3
 4

 Output #0, avi, to 'C:\Documents and Settings\Josh\Desktop\Microcirc working\South.avi':
     Stream #0.0: Video: mpeg4, yuv420p, 640x480, q=2-31, 19660 kb/s, 90k tbn, 24 tbc

That is the entire error code. The integers before hand are the count printout from the program (print n).

I have looked online at several discussion boards, and have found that error code as a part of longer error messages. If I change the AVI codec to something that I do not have installed on my computer, I get a longer error message stating that the codec is missing.

I am sure there is a simple answer, but I am tired of butting my head against the wall. All comments are appreciated.

Thanks Josh

0

精彩评论

暂无评论...
验证码 换一张
取 消