In the differential test, we found that the arm with fast motion is good, but the effect is not good for the body with little motion. When we accidentally swing the camera, we found that it can obtain the contour after the difference, further, if the camera does not move and the image is jittery, that is, the entire image is moved up to the left, so that the contour can be obtained in the difference, therefore, we have implemented this in opencv5.Algorithm. The test results are good.
Its advantage is a novel, simple, and computation method, because it does not need to calculate any gradient. If you use some well-intentioned and Sobel operators, it will be much slower, its disadvantage is that it introduces interference from other objects.
In fact, the greater significance is that in a static scenario, when we need to split those static objects, we may use this method to easily obtain the contour.
The algorithm is as follows:
// Use the frame difference method to obtain the contour
Int humanmotion: getcontour (iplimage * gray, iplimage * pre_grey)
{
Cvmat;
Cvmat * temp = cvgetmat (pre_grey, & mat, 0, 2 );
Int shift_x = 1;
Int shift_y = 1;
For (INT x = 0; x <mat. rows-shift_x; X ++)
{
For (INT y = 0; y <mat. step-shift_x; y ++)
{
Int value = mat. Step * x + y;
Int value2 = mat. Step * (x + shift_x) + Y + shift_y;
Mat. Data. PTR [value] = mat. Data. PTR [value2];
}
}
Cvabsdiff (Gray, pre_grey, abs_image );
Cvthreshold (abs_image, abs_image, 20,255, cv_thresh_binary );
Return 0;
}