Skip to content

Commit 94d33c5

Browse files
authored
Add files via upload
1 parent 068f317 commit 94d33c5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

color_detection.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import numpy as np
2+
import argparse
3+
import cv2
4+
5+
ap = argparse.ArgumentParser()
6+
ap.add_argument("-i", "--image", required=True, help = "path to image")
7+
args = vars(ap.parse_args())
8+
9+
image = cv2.imread(args["image"])
10+
11+
boundaries = [
12+
([17, 15, 100], [50, 56, 200]),
13+
([86, 31, 4], [220, 88, 50]),
14+
([25, 146, 190], [62, 174, 250]),
15+
([103, 86, 65], [145, 133, 128])
16+
]
17+
18+
for (lower, upper) in boundaries:
19+
lower = np.array(lower, dtype = "uint8")
20+
upper = np.array(upper, dtype = "uint8")
21+
22+
mask = cv2.inRange(image, lower, upper)
23+
output = cv2.bitwise_and(image, image, mask = mask)
24+
25+
cv2.imshow("images", np.hstack([image, output]))
26+
cv2.waitKey(0)

0 commit comments

Comments
 (0)