Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Working with video files

Hi All, I'm a very new user to SimpleCV but am finding the program very useful so far. I'm just looking for a bit of help using SimpleCV to process an existing video file that I have.

All the examples and help I have found are for streaming directly from Camera's whereas I'm interested in analysing a previously existing video.

I have a code that I have managed to get to work however I'm sure there is a better/more efficient way of doing this and was hoping for some input from some more advanced users.

I'm using a VirtualCamera to read in my video file and using that to do my processing. I am doing circle tracking on three balls in the video and that is all working fine. The problem/complication I'm having is my loop in which I do my processing doesn't exit nicely. If I let it run to the end of the video the program will crash as the img Image in my code cannot be used to do my dist.ColorDistance line as there is no data in the image (it has read in a blank Image from a non-existing video frame).

I have implemented a messy workaround (if img.getBitmap() .....) but I was hoping for a nicer way to do this.

Thanks in advance for your help and advice!

video = scv.VirtualCamera('juggling_short.mp4', 'video')
display = scv.Display()
while display.isNotDone():
    img = video.getImage()
    if img.getBitmap() == '': display.done = True
    else: 
        dist = img.colorDistance(scv.Color.RED)
        segmented = dist.stretch(0,50)
        inverted = segmented.invert()
        blobs = inverted.findBlobs()
        if blobs:
            circles = blobs.filter([b.isCircle(0.8) for b in blobs])
            if circles:
                for ball in circles:
                    img.drawCircle((ball.x, ball.y), ball.radius(), scv.Color.BLUE,3)
        img.show()
    if display.mouseRight: display.done = True
display.quit()