Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import numpy as np
- import cv2
- UNIW, UNIH = 320, 240
- if len(sys.argv) != 3: raise Exception("Two files should be specified.")
- targetFile, captureFile = sys.argv[1:]
- # get target, resize, generate mask
- target = cv2.imread(targetFile , cv2.IMREAD_UNCHANGED)
- if len(target[0][0]) != 4: raise Exception("Image should have 4 channels.")
- target = cv2.resize(target, (UNIW, UNIH), interpolation=cv2.INTER_NEAREST)
- [lower, upper] = [np.array(bounds, dtype="uint8") for bounds in [[0, 0, 0, 1], [255, 255, 255, 255]]]
- mask = cv2.inRange(target, lower, upper)
- target = cv2.cvtColor(target, cv2.COLOR_BGRA2BGR)
- # get capture, resize
- capture = cv2.imread(captureFile, cv2.IMREAD_COLOR)
- capture = cv2.resize(capture, (UNIW, UNIH), interpolation=cv2.INTER_NEAREST)
- # compare
- error = cv2.norm(target, capture, cv2.NORM_L2, mask) # component-wise norm
- normaliser = (3 * np.count_nonzero(mask) * 255 * 255) ** 0.5
- result = 1 - (error / normaliser)
- print(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement