Newbie to CV here so sorry of this is basic. Here's the deal, I have a program that I run many times. and each run I produce a screenshot. I need to compare screenshots from N-1 and N runs and make sure they aren't different in any dramatic way. Of course there are some minor changes like logos and pictures getting updated, etc.

SO far I've used something as simple as absdiff from opencv to highlight the difference regions and then use some sort of threshold to determine whether something passes or not. But I want to make it slightly intelligent but I'm not 100% sure how to proceed. Google hasn't yielded ghe best answers.

Essentially, I want to train the model on many different pairs of images and have the output be binary, yes or no depending on whether it should pass or not. In theory, I should be able to plug in 2 images and based on previous training, it should be able to tell me whether there is significant difference or not. What are some ways I might approach this, particularly with regards to what kinds of models to use.

The requirements here might seem amorphous but that's kinda the nature of the problem. the differences could be, in theory, anything. I am hoping that there will be patterns between different images and that a model would pick up on that. Things like the name of a document is 045 instead of 056 or a logo is slightly updated.


1 Answer 1


If your image just slightly changes, all you need is the simple algorithm, just find the keyword "k-Nearest Neighbor" or take a look at this link.

To locate where is the difference, you can find the difference by subtracting two images by this script:

def extract_diff(imageA, imageB):
    Find the different between two image:
        + Input: two RGB image
        + Output: binary image show different between two image
    Assume the different between two image in each channel will be bigger or equal 30
    subtract = imageB.astype(np.float32) - imageA.astype(np.float32)
    mask_motion = cv2.inRange(np.abs(subtract),(30,30,30),(255,255,255))
    # mask_motion[mask_motion==255] = 1 # scale to 1 to reduce computation
    return mask_motion

And locate where the position with value 255 in the image. Next time you should this kind of question in the stack overflow community, there is a more active community, they can give you a better solution than mine.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .