Advertisement
Pyorot

Autosplit Static Diff

Mar 20th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. import sys
  2. import numpy as np
  3. import cv2
  4.  
  5. UNIW, UNIH = 320, 240
  6.  
  7. if len(sys.argv) != 3: raise Exception("Two files should be specified.")
  8. targetFile, captureFile = sys.argv[1:]
  9.  
  10. # get target, resize, generate mask
  11. target = cv2.imread(targetFile , cv2.IMREAD_UNCHANGED)
  12. if len(target[0][0]) != 4: raise Exception("Image should have 4 channels.")
  13. target = cv2.resize(target, (UNIW, UNIH), interpolation=cv2.INTER_NEAREST)
  14. [lower, upper] = [np.array(bounds, dtype="uint8") for bounds in [[0, 0, 0, 1], [255, 255, 255, 255]]]
  15. mask = cv2.inRange(target, lower, upper)
  16. target = cv2.cvtColor(target, cv2.COLOR_BGRA2BGR)
  17.  
  18. # get capture, resize
  19. capture = cv2.imread(captureFile, cv2.IMREAD_COLOR)
  20. capture = cv2.resize(capture, (UNIW, UNIH), interpolation=cv2.INTER_NEAREST)
  21.  
  22. # compare
  23. error = cv2.norm(target, capture, cv2.NORM_L2, mask)    # component-wise norm
  24. normaliser = (3 * np.count_nonzero(mask) * 255 * 255) ** 0.5
  25. result = 1 - (error / normaliser)
  26.  
  27. print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement