title: How to verify that two images are exactly identical?
body: <p>I am writing an opencv program where I track position of an object by use of a usb camera. To make sure I get as high frame rate as possible with the camera I am using I made a threaded process that read the images from the camera. The image processing is done in another loop which also writes the object position to the file.</p>
  
  <p>Now I want a way to avoid processing the same frame multiple times. So I thought I could compare the image just processed with that available from the the video stream thread.</p>
  
  <p>First I tried to use if frame1 == frame2, but got error message that "the truth value of an array with more than one element is ambiguous. Use a.any() or a.all()." 
  After some googling I found cv2.compare and the flag CMP_EQ. Made a sample code, and made it work in some way. However, my question is. How could this be done in an easier or better way?</p>
  
  <pre><code>import cv2
  
  cv2.namedWindow('image1', cv2.WINDOW_NORMAL)
  cv2.namedWindow('image2', cv2.WINDOW_NORMAL)
  
  frame1 = cv2.imread("sample1.png")
  frame2 = frame1
  frame3 = cv2.imread("sample2.png")
  
  compare1 = cv2.compare(frame1,frame2,0)
  compare2 = cv2.compare(frame1,frame3,0)
  
  cv2.imshow('image1', compare1)
  cv2.imshow('image2', compare2)
  
  if compare1.all():
      print "equal"
  else:
      print "not equal"
  
  if compare2.all():
      print "equal"
  else:
      print "not equal"
  
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  </code></pre>