-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathOpenCV.py
88 lines (70 loc) · 2.41 KB
/
OpenCV.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from org.myrobotlab.image import Util
# start a opencv service
opencv = Runtime.start("opencv","OpenCV")
#gui.setActiveTab("opencv")
# add python as a listener to OpenCV data
# this tells the framework - whenever opencv.publishOpenCVData is invoked
# python.onOpenCVData will get called
python = Runtime.start("python","Python")
python.subscribe("opencv", "publishOpenCVData")
# call back - all data from opencv will come back to
# this method
def onOpenCVData(data):
# check for a bounding box
if data.getBoundingBoxArray() != None:
for box in data.getBoundingBoxArray():
print("bounding box", box.x, box.y, box.width, box.height)
# to capture from an image on the file system
# opencv.captureFromImageFile("C:\Users\grperry\Desktop\mars.jpg")
# not for you, it's for test
if ('virtual' in globals() and virtual):
opencv.setMinDelay(500)
opencv.setFrameGrabberType("org.bytedeco.javacv.FFmpegFrameGrabber")
opencv.setInputSource("file")
opencv.setInputFileName(Util.getRessourceDir()+"OpenCV/testData/monkeyFace.mp4")
opencv.capture()
#### LKOpticalTrack ####################
# experiment with Lucas Kanade optical flow/tracking
# adds the filter and one tracking point
opencv.addFilter("LKOpticalTrack")
opencv.setDisplayFilter("LKOpticalTrack")
# attempt to set a sample point in the middle
# of the video stream - you can
opencv.invokeFilterMethod("LKOpticalTrack","samplePoint", 0.5, 0.5)
sleep(4)
opencv.removeFilters()
opencv.addFilter("FaceDetect")
opencv.setDisplayFilter("FaceDetect")
# attempt to set a sample point in the middle
# of the video stream - you can
sleep(4)
opencv.removeFilters()
#### PyramidDown ####################
# scale the view down - faster since updating the screen is
# relatively slow
opencv.addFilter("PyramidDown")
opencv.setDisplayFilter("PyramidDown")
sleep(4)
# adding a second pyramid down filter - we need
# a unique name - so we'll call it PyramidDown2
opencv.addFilter("PyramidDown2","PyramidDown")
opencv.setDisplayFilter("PyramidDown2")
sleep(4)
opencv.removeFilters()
#### Canny ########################
# adding a canny filter
opencv.addFilter("Canny")
opencv.setDisplayFilter("Canny")
sleep(4)
canny = opencv.getFilter("Canny")
# changing parameters
canny.apertureSize = 3
canny.lowThreshold = 10.0
canny.highThreshold = 200.0
sleep(2)
canny.apertureSize = 5
canny.lowThreshold = 10.0
canny.highThreshold = 100.0
sleep(4)
opencv.removeFilters()
opencv.stopCapture()