-
Notifications
You must be signed in to change notification settings - Fork 0
/
detect_color.py
59 lines (36 loc) · 1.33 KB
/
detect_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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# USAGE
# python detect_color.py --image pokemon_games.png
# import the necessary packages
import numpy as np
from pyimagesearch import imutils
import argparse
import cv2
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--logooo.PNG", help = "C:\Python27\logooo.PNG")
args = vars(ap.parse_args())
# load the image
image = cv2.imread("pokemon_games.png")
ret1,th1 = cv2.threshold(image,127,255,cv2.THRESH_BINARY)
hist = cv2.calcHist([th1],[0],None,[256],[0,256])
cv2.imshow('Output_threshold',hist)
ratio = image.shape[0] / 500.0
orig = image.copy()
image = imutils.resize(image, height = 500)
#cap = cv2.VideoCapture(0)
# define the list of boundaries
boundaries=[([17, 15, 100], [50, 56, 200])]
# loop over the boundaries
for (lower, upper) in boundaries:
#create NumPy arrays from the boundaries
lower = np.array(lower, dtype = "uint8")
upper = np.array(upper, dtype = "uint8")
# find the colors within the specified boundaries and apply
# the mask
mask = cv2.inRange(image, lower, upper)
output = cv2.bitwise_and(image, image, mask = mask)
#print output
cv2.imshow('Output_Final',output)
# show the images
#cv2.imshow("images", np.hstack([image, output]))
cv2.waitKey(0)