如何比较两个图像并使用JavaCV突出显示差异?如果有人在技术上实现,请帮助。我使用了cvAbsDiff方法,但没有得到正确的结果。
下面提到了代码段:
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);