Skip to content

Commit 3f2f774

Browse files
committed
Initial code upload
Mostly just fun scripts for now. Will organize later.
1 parent 9bec301 commit 3f2f774

13 files changed

+184
-0
lines changed

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>2914FRC2014</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

.pydevproject

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?><pydev_project>
3+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
4+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
5+
</pydev_project>

hotornottests/HOT.JPG

79.7 KB
Loading

hotornottests/NOT.JPG

80.1 KB
Loading

hotornottests/Thumbs.db

31.5 KB
Binary file not shown.

hotornottests/damn.jpg

52.3 KB
Loading

pyballfinder/.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>pyballfinder</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.python.pydev.PyDevBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.python.pydev.pythonNature</nature>
16+
</natures>
17+
</projectDescription>

pyballfinder/.pydevproject

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<?eclipse-pydev version="1.0"?><pydev_project>
3+
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
4+
<path>/${PROJECT_DIR_NAME}</path>
5+
</pydev_pathproperty>
6+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
7+
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
8+
</pydev_project>

pyballfinder/ballFinder.py

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
''' v 0.1 - It tracks two objects of blue and yellow color each '''
2+
3+
import cv2
4+
import numpy as np
5+
6+
def getthresholdedimg(hsv):
7+
redLow = cv2.inRange(hsv,np.array((150,50,50)),np.array((180,200,200)))#in opencv, HSV is 0-180,0-255,0-255
8+
redHigh = cv2.inRange(hsv,np.array((0,50,50)),np.array((30,200,200)))
9+
red = cv2.add(redLow,redHigh)
10+
return red
11+
12+
c = cv2.VideoCapture(0)
13+
width,height = c.get(3),c.get(4)
14+
print "frame width and height : ", width, height
15+
storage = cv2.cv.CreateMat(image.width, 1, cv.CV_32FC3)
16+
17+
while(1):
18+
_,f = c.read()
19+
f = cv2.flip(f,1)
20+
blur = cv2.medianBlur(f,5)
21+
hsv = cv2.cvtColor(f,cv2.COLOR_BGR2HSV)
22+
img = getthresholdedimg(hsv)
23+
erode = cv2.erode(img,None,iterations = 1)
24+
#dilate = cv2.dilate(erode,None,iterations = 1)
25+
26+
#contours,hierarchy = cv2.findContours(dilate,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
27+
circles=cv2.HoughCircles(erode,)
28+
29+
for cnt in contours:
30+
x,y,w,h = cv2.boundingRect(cnt)
31+
cx,cy = x+w/2, y+h/2
32+
33+
if 20 < hsv.item(cy,cx,0) < 30:
34+
cv2.rectangle(f,(x,y),(x+w,y+h),[0,255,255],2)
35+
print "yellow :", x,y,w,h
36+
elif 100 < hsv.item(cy,cx,0) < 120:
37+
cv2.rectangle(f,(x,y),(x+w,y+h),[255,0,0],2)
38+
print "blue :", x,y,w,h
39+
40+
cv2.imshow('img',f)
41+
42+
if cv2.waitKey(25) == 27:
43+
break
44+
45+
cv2.destroyAllWindows()
46+
c.release()

pyballfinder/ballFinder.pyc

1.88 KB
Binary file not shown.

pyballfinder/hotornot.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import cv2
2+
import numpy as np
3+
"""
4+
Convert image to HSV plane using cvtColor() function
5+
Extract red and blue colors from it using inRange() function
6+
Apply erosion and dilation to avoid noise using erode() and dilate() functions
7+
Find Contours using findContours() function
8+
Draw the contours using drawContours() function.
9+
"""
10+
11+
c = cv2.VideoCapture(0)
12+
width,height = c.get(3),c.get(4)
13+
14+
def getthresholdedimg(hsv):
15+
return cv2.inRange(hsv,np.array((22,20,200)),np.array((37,240,255)))#in opencv, HSV is 0-180,0-255,0-255
16+
17+
while(1):
18+
_,capture = c.read()
19+
capture = cv2.flip(capture,1)
20+
21+
# Convert image to HSV plane using cvtColor() function
22+
hsvcapture = cv2.cvtColor(capture,cv2.COLOR_BGR2HSV)
23+
24+
# turn it into a binary image representing yellows
25+
inrangepixels = getthresholdedimg(hsvcapture)
26+
27+
# Apply erosion and dilation to avoid noise using erode() and dilate() functions
28+
erode = cv2.erode(inrangepixels,None,iterations = 3)
29+
dilate = cv2.dilate(erode,None,iterations = 5)
30+
31+
###
32+
# count yellows
33+
34+
yellows = cv2.countNonZero(dilate)
35+
36+
37+
if(yellows>2000):
38+
cv2.putText(capture,"HOT",(0,450),cv2.FONT_HERSHEY_SIMPLEX,10,(0,0,255))
39+
else:
40+
cv2.putText(capture,"NOT",(0,450),cv2.FONT_HERSHEY_SIMPLEX,10,(0,0,255))
41+
cv2.imshow('yellow',dilate)
42+
cv2.imshow('capture',capture)
43+
44+
if cv2.waitKey(25) == 27:
45+
break
46+
47+
cv2.destroyAllWindows()
48+
c.release()

pyballfinder/test.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import cv2
2+
import numpy as np
3+
"""
4+
Convert image to HSV plane using cvtColor() function
5+
Extract red and blue colors from it using inRange() function
6+
Apply erosion and dilation to avoid noise using erode() and dilate() functions
7+
Find Contours using findContours() function
8+
Draw the contours using drawContours() function.
9+
"""
10+
11+
c = cv2.VideoCapture(0)
12+
width,height = c.get(3),c.get(4)
13+
14+
def getthresholdedimg(hsv):
15+
red = cv2.inRange(hsv,np.array((175,140,50)),np.array((180,180,200)))#in opencv, HSV is 0-180,0-255,0-255
16+
#redHigh = cv2.inRange(hsv,np.array((0,50,50)),np.array((30,200,200)))
17+
#red = cv2.add(redLow,redHigh)
18+
return red
19+
20+
while(1):
21+
_,capture = c.read()
22+
capture = cv2.flip(capture,1)
23+
24+
# Convert image to HSV plane using cvtColor() function
25+
hsvcapture = cv2.cvtColor(capture,cv2.COLOR_BGR2HSV)
26+
27+
# Extract red and blue colors from it using inRange() function
28+
inrangepixels = getthresholdedimg(hsvcapture)
29+
30+
# Apply erosion and dilation to avoid noise using erode() and dilate() functions
31+
erode = cv2.erode(inrangepixels,None,iterations = 3)
32+
dilate = cv2.dilate(erode,None,iterations = 10)
33+
34+
###
35+
36+
cv2.imshow('binaryImg',dilate)
37+
cv2.imshow('capture',capture)
38+
39+
if cv2.waitKey(25) == 27:
40+
break
41+
42+
cv2.destroyAllWindows()
43+
c.release()

pyballfinder/test.pyc

1022 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)