
cap >> image;
if( !image.data ) exit(0);
backgroundDiff( image, mask );
// A simple visualization is to write to the red channel
//
cv::split( image, Igray );
Igray[2] = cv::max( mask, Igray[2] );
cv::merge( Igray, image );
cv::imshow( "Example9_2", image );
if( cv::waitKey(7) == 0x20 ) break;
}
exit(0);
}
We’ve just seen a simple method of learning background scenes and segmenting foreground objects. It will
work well only with scenes that do not contain moving background components (it would fail with a waving
curtain or waving trees). It also assumes that the lighting remains fairly constant (as in indoor static
scenes). You can look ahead to
X
Figure 9-6X to check the performance of this averaging method.
12BAccumulating Means, Variances, and Covariances
The averaging background method just described made use the accumulation operator,
cv::Mat::operator+=() to do what was essentially the simplest possible thing: to sum up a bunch of
data that we could then normalize into an average. The average is a convenient statistical quantity for a lot
of reasons, of course, but one often overlooked advantage of the average is the fact that it can be computed
incrementally in this way.
F
7
F This means that we can do processing on line without needing to accumulate all
of the data before analyzing. We will now consider a slightly more sophisticated model, which can also ...