examples/computer_vision/opencvExample/README.md
OpenCV is a powerful open-source library for image processing and computer vision. This example demonstrates one particularly common workflow in new-media art: performing background subtraction, blob detection and contour tracing. This is immensely useful for locating objects or people that have entered a scene!
After studying this example, you'll understand how to:
When launching this app, you'll see a window that displays five different stages in processing a video.
ofVideoPlayer), this video is stored in colorImg, an ofxCvColorImage.grayImage object, which is an instance of an ofxCvGrayscaleImage. It's easy to miss the grayscale conversion; it's done implicitly in the assignment grayImage = colorImg; (line 48 in the ofApp.cpp file) using operator overloading of the = sign. In this example, all of the subsequent image processing is done with grayscale (rather than color) images.ofxCvContourFinder has been tasked to findContours() in the binarized image. It does this by identifying blobs of white pixels that meet certain area requirements -- and then tracing the contours of those blobs into an ofxCvBlob outline of (x,y) points. The app shows the contour of each blob in cyan, and also shows the bounding rectangle of those points in magenta. Note: The contour is a vector-based representation, and can be used for all sorts of further geometric play....There are a few user-modifiable settings in this app:
space bar will capture a fresh image of the background.+ and - keys will adjust the threshold used in the absolute differencing operation. The greater the threshold value, the more different a pixel needs to be from the background in order to be considered part of the "foreground".One more thing. In line 7 of the ofApp.h file, you'll see the following line commented out:
//#define _USE_LIVE_VIDEO
If you uncomment this line, the app will use your computer's built-in webcam instead of a stored video file! It accomplishes this by swapping out the ofVideoPlayer with an ofVideoGrabber.
This example links against the ofxOpenCv core addon. It uses the following classes from that addon:
In addition, this example uses the following classes to access video from a live camera and/or a pre-stored file: