-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimage_check.py
More file actions
38 lines (32 loc) · 1.12 KB
/
image_check.py
File metadata and controls
38 lines (32 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import sys
import cv2
import numpy as np
import urllib.request
def usage():
print("This file needs to be called with two parameters.")
print("Please call it in the form:")
print("python3 image_check image.jpg URL\n")
sys.exit()
def main(image, url):
original = cv2.imread(image)
req = urllib.request.urlopen('https://hips.hearstapps.com/ghk.h-cdn.co/assets/16/08/gettyimages-464163411.jpg')
arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
dupe = cv2.imdecode(arr, -1) # 'Load it as it is'
if original.shape == dupe.shape:
print("Images have same size and channels")
diff = cv2.subtract(original, dupe)
b, g, r = cv2.split(diff)
if cv2.countNonZero(b) == 0 and cv2.countNonZero(g) == 0 and cv2.countNonZero(r) == 0:
print("The images are completely equal")
else:
print("The images are not the same")
else:
print("The images are not the same")
dupe = None
if __name__ == "__main__":
if len(sys.argv) == 1:
usage()
else:
image = sys.argv[1]
url = sys.argv[2]
main(image, url)