Manipulating video with OpenCV
In the last recipe of this chapter, we'll take a look at how we can manipulate the incoming video from the webcam. We'll use brightness and contrast filters and blur a part of the image set by the ROI()
method you've learned about in the previous recipe.
How to do it...
The beginning of the sketch is similar to the ones you've written in previous recipes. You should recognize the following piece of code.
import hypermedia.video.*; OpenCV opencv; void setup() { size( 640, 480 ); opencv = new OpenCV( this ); opencv.capture( width, height ); }
In the draw()
function, we'll use some new methods to change the brightness and contrast of the webcam image. We'll also flip the image so that it appears upside-down and blurs part of the image.
void draw() { background( 0 ); opencv.read(); opencv.flip( OpenCV.FLIP_BOTH ); opencv.convert( GRAY ); opencv.brightness( 20 ); opencv.contrast( 80 ); opencv.ROI( 160, 120, 320, 240 ); opencv.blur...