I would like to create a program that compares two images. I need to take images from two different folders and compare that images if they are same or not. Then I want to print out as same or different. For example file 1 will have image1 and image 2 and image 3 , etc then file 2 will have image1,image2 and image3 etc . I need to do this python. How do I do this? Can someone help me? I am new to programming and I am new to python as well. I have tried the solution as below, but it did not work.
import cv2
import numpy as npfile1= "C:\Program Files (x86)\Python35-32\file1"
file2="C:\Program Files (x86)\Python35-32\file2"
for f1 in file1:image1 = cv2.imread(f1)for f2 in file2:image2 = cv2.imread(f2)difference = cv2.subtract(image1, image2)
result = not np.any(difference) #if difference is all zeros it will return False
if result is True:print("The images are the same")else:cv2.imwrite("result.jpg", difference)print ("the images are different")
but the above code seems to not working as expected. I know the for loops is not correct. I am new to python. Can you please let me what I am doing wrong here, please?
Actually, I am using this for comparing screen taken by automation and manual testing on mobile devices. The files are *.png. I manage to get this working with below code.
the above code you need top provide the image1 and image 2 on the command prompt.But I want python to take from images from files one in one location and images from other location and compare automatically. If the images are same then it should print as zero as now the above code response. If they are different then it will be no zero. The issue I am facing how I could take from two files and compare one by one from scripts. Eg. File1\Image1.png ==File2\ image1.png