-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun_color.py
40 lines (30 loc) · 1.1 KB
/
run_color.py
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
39
40
from pathlib import Path
import cv2
from color_detector import detect
import numpy as np
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("path")
path = parser.parse_args().path
blank = np.full((1080, 1920, 3), 255, dtype=np.uint8)
def show_image(title, image):
cv2.imshow(title, image)
cv2.waitKey(0)
cv2.destroyAllWindows()
def detect_and_show(file, color):
image = cv2.imread(file)
blurred, yuv, mask = detect(image, color, True)
output = cv2.bitwise_and(blank, blank, mask=mask)
show_image(
f"Detecting {color} in {file[len(path):]}", np.vstack((np.hstack((image, blurred)), np.hstack((yuv, output)))))
def detect_and_save(file, color):
image = cv2.imread(file)
result = detect(image, color)
cv2.imwrite(f"/Users/akshatmehta/Downloads/binary_yuv/{color}_{file[len(path):]}", result)
if __name__ == '__main__':
for img in Path(path).glob("**/*"):
img = str(img)
if "blue" in img or "both" in img:
detect_and_show(img, "blue")
if "red" in img or "both" in img:
detect_and_show(img, "red")