-
Notifications
You must be signed in to change notification settings - Fork 0
/
vision.py
38 lines (29 loc) · 1.16 KB
/
vision.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
from cscore import CameraServer
# Import OpenCV and NumPy
import numpy as np
def main():
cs = CameraServer.getInstance()
cs.enableLogging()
# Capture from the first USB Camera on the system
camera = cs.startAutomaticCapture()
camera.setResolution(640, 640)
# Get a CvSink. This will capture images from the camera
cvSink = cs.getVideo()
# (optional) Setup a CvSource. This will send images back to the Dashboard
outputStream = cs.putVideo("Name", 320, 240)
# Allocating new images is very expensive, always try to preallocate
img = np.zeros(shape=(240, 320, 3), dtype=np.uint8)
while True:
# Tell the CvSink to grab a frame from the camera and put it
# in the source image. If there is an error notify the output.
time, img = cvSink.grabFrame(img)
if time == 0:
# Send the output the error.
outputStream.notifyError(cvSink.getError());
# skip the rest of the current iteration
continue
#
# Insert your image processing logic here!
#
# (optional) send some image back to the dashboard
outputStream.putFrame(img)