-
Notifications
You must be signed in to change notification settings - Fork 0
/
ColorTesting.py
67 lines (58 loc) · 2.01 KB
/
ColorTesting.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
57
58
59
60
61
62
63
64
65
66
67
import cv2
import numpy as np
import os
import math
from picamera.array import PiRGBArray
import picamera
import time
import sys
from networktables import NetworkTables
import logging
import collections
import ctypes
def filterColors(image,minH,minS,minV,maxH,maxS,maxV):
#Filters out all colors but green; Returns color filtered image
HSVImg = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
mask = cv2.inRange(HSVImg,(minH,minS,minV),(maxH,maxS,maxV))
return mask
def null(x):
pass
def setupImageWindow(img):
cv2.namedWindow("Processed Image")
cv2.createTrackbar('minH', 'Processed Image',0,255,null)
cv2.createTrackbar('minS', 'Processed Image',0,255,null)
cv2.createTrackbar('minV', 'Processed Image',0,255,null)
cv2.createTrackbar('maxH', 'Processed Image',0,255,null)
cv2.createTrackbar('maxS', 'Processed Image',0,255,null)
cv2.createTrackbar('maxV', 'Processed Image',0,255,null)
while True:
minH = cv2.getTrackbarPos('minH','Processed Image')
minS = cv2.getTrackbarPos('minS','Processed Image')
minV = cv2.getTrackbarPos('minV','Processed Image')
maxH = cv2.getTrackbarPos('maxH','Processed Image')
maxS = cv2.getTrackbarPos('maxS','Processed Image')
maxV = cv2.getTrackbarPos('maxV','Processed Image')
colorImage = filterColors(img, minH,minS,minV, maxH,maxS,maxV)
small = cv2.resize(colorImage, (0,0), fx = 0.5, fy = 0.5)
cv2.imshow('Processed Image', small)
key = cv2.waitKey(0)
if key == ord('q'): # quit
return None
elif key == ord('g'): # good
break
# Try again on any other key
print
print minH
print minS
print minV
print maxH
print maxS
print maxV
print
pics = '/home/pi/test/AndromedaVision/WPI Pics'
for filename in os.listdir(pics):
fullFileName = os.path.join(pics, filename)
##print 'fullFileName', fullFileName
pic = cv2.imread(fullFileName)
setupImageWindow(pic)
cv2.destroyAllWindows()