piątek, 11 kwietnia 2014

OpenCV HOWTO: capture camera and do linear transformation on image

In this tutorial I'll try to show you how to do magic with OpenCV. I hope you've already installed it. We'll need some standard namespaces:

First, we have to create some Mat objects in which we'll store our images:
And variables to store linear transformation values:
Then we intialize capturing camera image:
And open windows to show results:
Then we have to open infinite loop. In each iteration we have to capture the image from camera:
We can also make it gray:
If we want to get negative image, we have to subtract the image pixels values from 255 (because 255 is maximum value):
If we want to get color negative image, we have to subtract the image pixels values in all dimensions (3) from 255:
For linear transformation we have to calculate each dimension of each pixel. If we have to increase (decrease) contrast, we have to multiply source value by value grater than 1 (smaller than 1). Adding (subtracting) value to the source gives increased (decreased) brightness:
Next we want to show our images:
At the end, we want to manipulate the values to linear transformation by pressing arrows or pressing ESC to leave the application.
That's all, hope you'll find it useful!