A Simple Transformation
Great, so now you can use OpenCV to create your own video player, which will not be much different from countless video players out there already. But we are interested in computer vision, and we want to do some of that. Many basic vision tasks involve the application of filters to a video stream. We will modify the program we already have to do a simple operation on every frame of the video as it plays.
One particularly simple operation is the smoothing of an image, which effectively reduces the information content of the
image by convolving it with a Gaussian or other similar kernel function. OpenCV makes such convolutions
exceptionally easy to do. We can start by creating a new window called "Example4-out",
where we can display the results of the processing. Then, after we have called cvShowImage() to display the newly captured frame in the input
window, we can compute and display the smoothed image in the output window. See Example 2-4.
Example 2-4. Loading and then smoothing an image before it is displayed on the screen
#include "cv.h" #include "highgui.h" void example2_4( IplImage* image ) // Create some windows to show the input // and output images in. // cvNamedWindow( "Example4-in" ); cvNamedWindow( "Example4-out" ); // Create a window to show our input image // cvShowImage( "Example4-in", image ); // Create an image to hold the smoothed output // IplImage* out = cvCreateImage( cvGetSize(image), IPL_DEPTH_8U, 3 ); // Do the smoothing // cvSmooth( image, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access