OpenCV More with cameras.
In last tutorial we learn how to get frames of our camera, now we go to learn some basic OpenCV functions to work with our captured frames or video. There is nothing special, but it's the first steps to introduce to work with OpenCV
Imagine we want create a basic OpenCV program that get a video o camera capture and process the images to get a binary image difference between actual frame and last frame.
Then we have a actual image, lastImage, diffImage where we store the difference images, and the bitImage result that are IplImage instance.
Whe need create these variables and initialize with cvCreateImage, this function create and allocate in memory the structure and headers of our image, this function need as attribute image size, depth and number of channels. We get frame as reference to initialize the variables.
The frame whe get sure is a RGB image, but we go to working with gray level images the we need conver captured frame to Gray Level. The cvCvtColor conver color spaces of image to another and is defined:
- src is the source 8-bit (8u), 16-bit (16u) or single-precision floating-point (32f) image. dst is the destination image of the same data type as the source one. The number of channels may be different. And code is color conversion operation that can be specified using CV_<src_color_space>2<dst_color_space> constants
We can get a new copy in memory of image withcvCloneImage
To get the image differences we use cvAbsDiff function, to get absolute diference between images:
The function definition
- Where src1 is the first source array. src2 is the second source array, and dst is the destination array.
Then to finish we only need get a threshold of image, and we do it with cvThreshold function
And this function have this definition:
- Where src is source array (single-channel, 8-bit of 32-bit floating point), dst is destination array; must be either the same type as
src
or 8-bit, threshold is the threshold value, max_value is the maximum value to use withCV_THRESH_BINARY
andCV_THRESH_BINARY_INV
thresholding types, and threshold_type is thresholding type
This is the main loop program: