How can I use JavaCV to compare two image and spot the differences pixel-wise

728 views Asked by At

How can I compare two images and highlight the differences using JavaCV? If anyone has implemented technically, please help.I had used cvAbsDiff method, but not getting proper result.

The Code Snippet is mentioned below :

IplImage loadedImageOne = cvLoadImage("D:\\Users\\vmullick\\Desktop\\Mavuno2.jpg");
CvSize cvSizeOne = cvSize(loadedImageOne.width(), loadedImageOne.height());
IplImage iplImageCreatedOne = cvCreateImage(cvSizeOne, loadedImageOne.depth(), 1);

// cvShowImage("Before Result", iplImageCreatedOne);
// cvWaitKey(0);

IplImage loadedImageTwo = cvLoadImage("D:\\Users\\vmullick\\Desktop\\Mavuno3.jpg");
CvSize cvSizeTwo = cvSize(loadedImageOne.width(), loadedImageTwo.height());
IplImage iplImageCreatedTwo = cvCreateImage(cvSizeTwo, loadedImageTwo.depth(), 1);

IplImage iplImageCreatedThree = cvCreateImage(cvSizeOne, loadedImageOne.depth(), 1);

cvAbsDiff(iplImageCreatedOne, iplImageCreatedTwo, iplImageCreatedThree);
cvWaitKey(0);

cvCanny(iplImageCreatedThree, iplImageCreatedThree, 10, 30, 3);

CvSeq cvSeqOfAbsDiff = new CvSeq();
CvMemStorage memory = CvMemStorage.create();

CvScalar color = CvScalar.BLUE;

cvFindContours(iplImageCreatedThree, memory, cvSeqOfAbsDiff, Loader.sizeof(CvContour.class), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);


for (CvSeq c = cvSeqOfAbsDiff; c != null && !c.isNull(); c = c.h_next()) {

    double area = cvContourArea(c, CV_WHOLE_SEQ, 0);
    if (area < 100) {
        continue;
    }

    CvRect rect = cvBoundingRect(c, 0);
    cvRectangle(loadedImageOne, cvPoint(rect.x(), rect.y()), cvPoint(rect.x() + rect.width(), rect.y() + rect.height()), color, 2, 8, 0);

}

cvShowImage("Result", loadedImageOne);
cvWaitKey(0);
0

There are 0 answers