OpenCV + Python

In order to build the display wall, potentially each Pi will need to be able to grab a frame from a video file and display a section of it. So the first step is grabbing and displaying one frame on one Pi. OpenCV (Open Computer Vision) has the capabilities to do this, but it doesn’t come installed on the Raspian OS. So here is where my fun began:

To install OpenCV and the Python bindings for it I followed the instructions found on this website.

However I found an error in the last section of code, specifically the “cmake” line, it should read as follows:


The difference is the”NEW_” between “BUILD_” and “PYTHON”.

Let the “make” command run overnight. It took the two Pies I was running around 12 hours each to compile the libraries. My guess as to why it took so long is because the limited amount of RAM on the devices.

Now to grab a frame! I found this code on a StackOverflow post and looked up the OpenCV function calls to actually figure out what it’s doing.

#!/usr/bin/env python
import as cv
import sys
files = sys.argv[1:]
for f in files:
    printf f
    capture = cv.CaptureFromFile(f)
    print capture
    frame = cv. QueryFrame(capture)
    print cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_WIDTH)
    print cv.GetCaptureProperty(capture, cv.CV_CAP_PROP_FRAME_HEIGHT)
    for i in xrange(10):
        print i
        # this frame can be written to a file
        frame = cv.QueryFrame(capture)
        if frame:
            print frame

I downloaded a few different small video files. A .avi, .m4v, .mpg, .mp4

When executed, I ran into the following error:

GLib-GObject-CRITICAL **: g_object_set: assertion 'G_IS_OBJECT (object)' failed


Leave a Reply

Your email address will not be published. Required fields are marked *