0
from skimage.measure import structural_similarity as ssim
import matplotlib.pyplot as plt
import numpy as np
import cv2
import time
img_counter=0
flag=False
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
return err
def compare_images(imageA, imageB):
# compute the mean squared error and structural similarity
# index for the images
m = mse(imageA, imageB)
s = ssim(imageA, imageB)
if m > 150 or s < 0.90:
print "object is detected"
flag=True
while True:
original = cv2.imread("/home/lingesh/last_try/images/0.jpg")
shopped = cv2.imread("/home/lingesh/last_try/images/{}.jpg".format(img_counter+1))
# convert the images to grayscale
original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
shopped = cv2.cvtColor(shopped, cv2.COLOR_BGR2GRAY)
compare_images(original, shopped)
if flag==True
break