OpenCV Lections: 7. Working With Camera. Background and Motion Analysis
OpenCV Lections: 7. Working With Camera. Background and Motion Analysis
http://people.rit.edu/andpph/photofile-misc/strobe-motion-ta-08.jpg
www.uralvision.blogspot.com [email protected]
USU / IMM Fall 2010
Working with the camera
Getting frames from the camera
VideoCapture capture; // A class to work with cameras and videos
capture.open (0); // Open the first chamber (numbered from 0)
// But if you specify a string VideoCapture capture.open ("myfile.avi"); - will read the avi-file
Must be at least 4 points to search for perspective projection. In this case any point should
not lie on one line.
Note: the coordinates are real numbers, which improves the accuracy of the result.
You can use the sub-pixel methods that calculate the position of objects with an accuracy
higher than pixel.
src [0] = cv:: Point2f (..., ...); // coordinates of the corners of the image
src [1] = cv:: Point2f (..., ...); // should go clockwise from top left corner
src [2] = cv:: Point2f (..., ...); // - in accordance with dst, see below
src [3] = cv:: Point2f (..., ...);
dst [0] = cv:: Point2f (0, 0) // the resulting point; w and h- The size of the result
dst [1] = cv:: Point2f (w, 0);
dst [2] = cv:: Point2f (w, h);
dst [3] = cv:: Point2f (0, h);
Idea: store the image background and then consider the difference between shots with the
camera from the stored images.
A more advanced method - "code book", he remembers the brightness of the background
in each pixel for a while, that allows to deal with objects such as opening doors.
Problems:
- Rapid changes in lighting - should be specifically
consider
- The shadows of objects are often perceived as
no background, which is usually undesirable, so
also be specially taken into account (through the color analysis).
2. Adaptive learning
A few seconds later the object came into the picture becomes the background. For some
tasks it is good.
Plus - no need to specifically construct a situation where there is no one in the frame for
storing the background.
There are more sophisticated algorithms automatically calculate the background with the
help of several accounting staff.
3.Using data on the depth
1. Stereo camera
2. Camera with the calculation of flight time (based on a laser rangefinder, time of filght
cameras)
3. Kinect
http://www.ultimategraphics.co.jp/jp/images/stories/ultimate/BCC/optical.jpg
The main application of optical flow
1. Lucas-Kanade
Local method, which uses the Taylor expansion in time t in the neighborhood of each pixel
independently.
Dignity: Quickly calculated.
Shortcomings: "Aperture problem" - in areas with a uniform texture, works poorly due to
the fact that it is local.
Realized only in the C-version of OpenCV,cvCalcOpticalFlowLK.
2. Farneback
Local method used to calculate an approximation of the image by a polynomial function.
void calcOpticalFlowFarneback(
const Mat & prevImg, // first frame, an 8-bit single channel image
const Mat & nextImg, // second frame, the type and size as a prevImg
Mat & flow, // resulting flow will be of the type CV_32FC2
double pyrScale, // <1, the scale of the construction of the pyramid.0.5
int levels, // Number of levels of the pyramid5
int winsize, // window averaging. The more - the result
// More diffuse, but also more resistant to noise5
int iterations, // Number of iterations at each level of the pyramid 3
int polyN, // window size to calculate the approximation
// Polynomial7
double polySigma, // parameter is Gaussian for smoothing derivatives
// In the construction of approximation1.5
int flags // flags
//OPTFLOW_USE_INITIAL_FLOW- Do not use!
//OPTFLOW_FARNEBACK_GAUSSIAN- Use a Gaussian for the averaging
// Gives a more accurate result at the expense of quality.
)
Methods of calculating the optical flow
3. CLG