How to make image comparison in openCV more coarse
<p>I am writing a code on raspberry pi in python to compare two images using mean squared error. The project is an personal home security thing.</p>

<p>My main goal is to detect a change between the images that I capture from pi camera(if something is added to the current image or something removed from the image) but right now my code is too sensitive. It is affected by change in background lighting, which I do not want.</p>

<p>I have two options in front of me, to either scrape my current logic and start a new one or improve my current logic to account for these noise(if I can call them that). I am searching for ways to improve my logic but I wanted some guidance on how to go about it.</p>

<p>My biggest fear being, am I wasting time kicking a dead horse or should I just look for some other algorithm to detect a change in image or should I use edge detection</p>

<pre><code>    import numpy as np
import cv2
import os
from threading import Thread
######Function Definition########################################
def mse(imageA, imageB):
    # the 'Mean Squared Error' between the two images is the
    # sum of the squared difference between the two images;
    # NOTE: the two images must have the same dimension
    err = np.sum((imageA.astype("int") - imageB.astype("int")) ** 2)
    err /= int(imageA.shape[0] * imageA.shape[1])

    # return the MSE, the lower the error, the more "similar"
    # the two images are
    return err

def compare_images(imageA, imageB):
    # compute the mean squared error
    m = mse(imageA, imageB)
    print(m)


def capture_image():
        ##shell command to click photos
        os.system(image_args)

##original image Path variable
original_image_path= "/home/pi/Downloads/python-compare-two-images/originalimage.png"

##original_image_args is a shell command to click photos 
original_image_args="raspistill -o "+original_image_path+" -w 320 -h 240 -q 50 -t 500"
os.system(original_image_args)

##read the greyscale of the image in to the variable original_image
original_image=cv2.imread(original_image_path, 0)

##Three images
image_args="raspistill -o /home/pi/Downloads/python-compare-two-images/Test_Images/image.png -w 320 -h 240 -q 50 --nopreview -t 10 --exposure sports"
image_path="/home/pi/Downloads/python-compare-two-images/Test_Images/"
image1_name="image.png"

#created a new thread to take pictures
My_Thread=Thread(target=capture_image)

#Thread started
My_Thread.start()

flag = 0
while(True):
        if(My_Thread.isAlive()==True):
                flag=0
        else:
                flag=1
        if(flag==1):
                flag=0
                image1 = cv2.imread((image_path+image1_name), 0)
                My_Thread=Thread(target=capture_image)
                My_Thread.start()
                compare_images(original_image, image1)
</code></pre>