Ask Your Question
1

Compare two images and highlight the difference

asked 2015-07-04 17:30:42 -0600

BladeRunner gravatar image

Hi - First I'm a total n00b so please be kind. I'd like to create a target shooting app that allows me to us the camera on my android device to see where I hit the target from shot to shot. The device will be stationary with very little to no movement. My thinking is that I'd access the camera and zoom as needed on the target. Once ready I'd hit a button that would start taking pictures every x seconds. Each picture would be compared to the previous one to see if there was a change - the change being I hit the target. If a change was detected the two imaged would be saved, the device would stop taking picture, the image with the change would be displayed on the device and the spot of change would be highlighted. When I was ready for the next shot, I would hit a button on the device and the process would start over. If I was done shooting, there would be a button to stop.

Any help in getting this project off the ground would be greatly appreciated.

edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted
1

answered 2015-07-06 09:37:52 -0600

Karthikeyan gravatar image

updated 2015-07-07 00:38:44 -0600

This will be a very basic algorithm just to evaluate your use case. It can be improved a lot.

(i) In your case, the first step is to identify whether there is a change or not between 2 frames. It can be identified by using a simple StandardDeviation measurement. Set a threshold for acceptable difference in deviation.

Mat prevFrame, currentFrame;

for(;;)
{
    //Getting a frame from the video capture device.
    cap >> currentFrame;

    if( prevFrame.data )
    {
         //Finding the standard deviations of current and previous frame.
         Scalar prevStdDev, currentStdDev;
         meanStdDev(prevFrame, Scalar(), prevStdDev);
         meanStdDev(currentFrame, Scalar(), currentStdDev);

          //Decision Making.
          if(abs(currentStdDev - prevStdDev) < ACCEPTED_DEVIATION)
          {
               Save the images and break out of the loop.
          }     
    }

    //To exit from the loop, if there is a keypress event.
    if(waitKey(30)>=0)
        break;

    //For swapping the previous and current frame.
    swap(prevFrame, currentFrame);
}

(ii) The first step will only identify the change in frames. In order to locate the position where the change occured, find the difference between the two saved frames using AbsDiff. Using this difference image mask, find the contours and finally mark the region with a bounding rectangle.

Hope this answers your question.

edit flag offensive delete link more

Comments

This worked for me.. Thanks for suggestion.

satheesh kumar gravatar imagesatheesh kumar ( 2018-10-05 00:46:34 -0600 )edit
0

answered 2015-07-05 07:47:29 -0600

Eduardo gravatar image

If you want to compare two image to spot the differences, I think that you can use Background Subtraction Methods, see the following tutorial: http://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html

edit flag offensive delete link more

Comments

And this video shows how to code it in python https://youtu.be/LNzC4NYYWdg

Nam G VU gravatar imageNam G VU ( 2017-05-23 02:05:12 -0600 )edit
0

answered 2016-01-02 00:07:32 -0600

AndyW gravatar image

I am an absolute newbie in this but I find this article very similar to what my endeavors are, and that is to use OpenCV to display differences between 2 images. My goal is to be able to automatically preprocess the 2 images like scaling, rotating, etc. or whatever is needed to make one image as similar to the other in terms of ROI and then display the differences if there are any.

I was told that I could use OpenCV for this and I would appreciate any guidance on how to do this in Delphi.

I am also willing to outsource this as a paid service to get me started on this.

[IMG]http://i64.tinypic.com/2lnb7rt.jpg[/IMG] [IMG]http://i67.tinypic.com/1zbgeoh.jpg[/IMG]

edit flag offensive delete link more
0

answered 2018-10-05 01:11:23 -0600

satheesh kumar gravatar image

This solution will help you.

    Core.absdiff(firstMat, secondMat, outputImageMat);

    List<MatOfPoint> contours = new ArrayList<>();

    Imgproc.cvtColor(outputImageMat, outputImageMat, Imgproc.COLOR_BGR2GRAY);
    Imgproc.findContours(outputImageMat, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

    for (int i = 0; i < contours.size(); i++) {
        Rect rect = Imgproc.boundingRect(contours.get(i));
        Imgproc.rectangle(secondMat, new Point(rect.x, rect.y), new Point(rect.x + rect.width,
                rect.y + rect.height), new Scalar(100, 0, 0, 255), 6);
    }
    outputImage.setImageBitmap(setMatToBitmap(secondMat));
edit flag offensive delete link more

Comments

Here setMatToBitmap(Bitmap bitmap) method is my own method to get bitmap from Mat.

satheesh kumar gravatar imagesatheesh kumar ( 2018-10-05 01:13:43 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-04 17:29:59 -0600

Seen: 16,440 times

Last updated: Oct 05 '18