I’ve been working on getting a camera to work on an Rpi.
I built opencv per the instructions found here:
apropos, I used the sources from https://github.com/opencv/opencv/releases
(hence, using 3.4.3)
I then built robotpy cscore per the instructions at https://robotpy.readthedocs.io/en/latest/install/cscore.html#install-cscore (non roborio platforms).
As you’ll see below, I have a couple print statements wrapped around the call to grabFrame. I get the 1st, but not the 2nd. So, it appears getFrame is seg-faulting.
Any idea what I am (or did) wrong?
Code looks like:
cs = CameraServer.getInstance() cs.enableLogging() cam = UsbCamera('logi c170', 0) cs.addCamera(cam) cam.setResolution(640, 480) # Get a CvSink. This will capture images from the camera cvSink = cs.getVideo(camera=cam) # (optional) Setup a CvSource. This will send images back to the Dashboard outputStream = cs.putVideo("Rectangle", 640, 480) # Allocating new images is very expensive, always try to preallocate img = np.zeros(shape=(480, 640, 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. print('grab') time, img = cvSink.grabFrame(img,0.5) print(time, img)
Output looks like:
INFO:nt:NetworkTables initialized in client mode DEBUG:nt.th:Started thread nt-dispatch-thread-0 DEBUG:nt.th:Started thread nt-client-thread-0 DEBUG:nt:client connected DEBUG:nt.th:Started thread nt-net-write-0 DEBUG:nt.th:Started thread nt-net-read-0 INFO:nt:CONNECTED roborio-1289-frc.local port 1735 (Robot) DEBUG:nt.th:Started thread entry-notifier-0 INFO:cscore:logi c170: Connecting to USB camera on /dev/video0 INFO:cscore:logi c170: set format 1 res 160x120 INFO:cscore:logi c170: Connecting to USB camera on /dev/video0 INFO:cscore:logi c170: set format 1 res 640x480 INFO:cscore:logi c170: set FPS to 30 INFO:cscore.cserver:CameraServer 'serve_Rectangle' listening on port 1181 grab Segmentation fault