I'm working with OpenCV (in Android NDK) and I have a problem. I want to find differences between two pictures, and than cut the difference. However, following output made difference bigger. I used images from this question CV - Extract differences between two images . And I tried to solve it but unsuccessfully. Here is the output
Mat& backgroundImage = *(Mat*) addrRgba;
Mat& currentImage = *(Mat*) addrRgba2;
Mat diffImage;
absdiff(backgroundImage, currentImage, diffImage);
Mat mask=currentImage.clone();
float threshold = 30.0f;
float dist;
for(int j=0; j<diffImage.rows; ++j)
for(int i=0; i<diffImage.cols; ++i)
{
if(diffImage.at<cv::Vec3b>(j,i)==Vec3b(0,0,0)){
Point center( i , j);
circle (mask,center,1,Scalar( 255, 255, 255 ),-1,9,0);
}
}
currentImage=mask;
FIRST IMAGE
SECOND IMAGE
RESULT
On the other hand , this code gives me output like this
Mat& backgroundImage = *(Mat*) addrRgba;
Mat& currentImage = *(Mat*) addrRgba2;
Mat diffImage;
absdiff(backgroundImage, currentImage, diffImage);
Mat gray;
cvtColor(diffImage,gray, COLOR_BGR2GRAY);
equalizeHist( gray, gray );
Mat mask=currentImage.clone();
cvtColor(mask,mask, COLOR_BGR2GRAY);
float threshold = 30.0f;
float dist;
for(int j=0; j<gray.rows; ++j)
for(int i=0; i<gray.cols; ++i)
{
cv::Vec3b pix = gray.at<cv::Vec3b>(j,i);
if(pix==Vec3b(0,0,0)){
Point center( i , j);
circle (mask,center,1,Scalar( 255, 255, 255 ),-1,9,0);
}
}
Mat maskedImage;
diffImage.copyTo(maskedImage,mask);
currentImage=mask;