I have an image of the background scene and an image of the same scene with objects in front. Now I want to create a mask of the object in the foreground with background sub
I think when I'm doing it like this I get the right results: (in the YCrCb colorspace) but accessing each px is slow so I need to find another algorithm
cv::Mat mask(image.rows, image.cols, CV_8U, cv::Scalar(0,0,0));
cv::Mat_::const_iterator itImage= image.begin();
cv::Mat_::const_iterator itend= image.end();
cv::Mat_::iterator itRef= refRoi.begin();
cv::Mat_::iterator itMask= mask.begin();
for ( ; itImage!= itend; ++itImage, ++itRef, ++itMask) {
int distance = abs((*itImage)[0]-(*itRef)[0])+
abs((*itImage)[1]-(*itRef)[1])+
abs((*itImage)[2]-(*itRef)[2]);
if(distance < 30)
*itMask = 0;
else
*itMask = 255;
}