Ask Your Question

Compare two images and highlight the difference

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

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

3 answers

Sort by ยป oldest newest most voted

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

Karthikeyan gravatar image

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

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;

    //Getting a frame from the video capture device.
    cap >> currentFrame;

    if( )
         //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.

    //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

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

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:

edit flag offensive delete link more


And this video shows how to code it in python

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

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

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.


edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 7,200 times

Last updated: Jul 07 '15