Example 3 - Smooth a video

From Devipedia

Jump to: navigation, search

At this point I'm already deviating from the book. Example three showed how to add a slider to your window that can be used to navigate the video. I'm more interested in apply effects, so I skipped to the fourth. I wanted to keep the structure similar to my last example, so here I've just created an out image, added a call to cvSmooth in order to apply a Gaussian filter, and sent the out frame to show image.

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


if __name__ == '__main__':

    cvNamedWindow("Example3", CV_WINDOW_AUTOSIZE)
    capture = cvCreateFileCapture(sys.argv[1])
   
    while True:
        frame = cvQueryFrame( capture )
        if frame == None:
            break

        out = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3)
        cvSmooth( frame, out, CV_GAUSSIAN, 3, 3)

        cvShowImage("Example3", out)
        c = cvWaitKey(33)
        if c == chr(27):  
            break       

    cvReleaseCapture(capture)
    cvDestroyWindow("Example3")

Personal tools