Log in

View Full Version : USB Camera issues


team-4480
04-01-2016, 17:53
Hi,

I tried to get the USB camera working last year and unfortunately that didn't pan out. I am back again with a little more determination and motivation to get the camera to work.

Our camera:
A Logitech C270 USB camera

Our problem:
No video feed whatsoever in the Driver Station(and yes we did try switching every mode on the DriverStation). The camera appears in the roboRIO web dashboard as "cam1".

Our forwarding code:

try:
self.camera = wpilib.USBCamera()
self.camera.startCapture()
self.camServ = wpilib.CameraServer()
self.camServ.startAutomaticCapture(self.camera)
except:
self.camera = None

The code is in Python but it should be similar to other languages.

Any suggestions or possible solutions are welcomed and very much appreciated! I have torn more hair out over this long issue than any other programming issue I've had.

timtim17
04-01-2016, 21:52
I don't have experience with RobotPy, but I think you need to specify the name of the camera when creating the USBCamera instance.

self.camera = wpilib.USBCamera("cam1")


Also, I don't think you need to call self.camera.startCapture(), because self.camServ.startAutomaticCapture(self.camera) calls it for you.

virtuald
05-01-2016, 00:45
My students wrote some code to use the USBCamera in RobotPy, but the USBCamera stuff is highly inefficient in python, if I recall correctly. Here's a link to some of their code. (https://github.com/frc1418/2015-vision/blob/master/scratchpad/robot.py)

I've never tried sending it to the Driver Station... but I feel like I remember the students doing it, and it worked.

However, if you're just trying to *see* the feed, I would recommend using mjpg-streamer instead. Here's a CD thread about that: http://www.chiefdelphi.com/forums/showthread.php?t=135737

And here's a gist (https://gist.github.com/virtuald/c8835244759e53314211) that contains scripts to make it work.

And if you want to read the images from mjpg-streamer using python and process it with OpenCV, the repo listed above has a bunch of code for that.

I'll be adding mjpg-streamer to the robotpy opkg feed for 2016, just haven't gotten around to it yet. Hopefully by the end of this week or week one.

team-4480
05-01-2016, 22:51
I think I will try using the mjpg-streamer on a Raspberry Pi 2 instead of the Rio. I don't feel like messing with the Rio just days before the launch in case I brick the Rio. My only concern with the Raspberry Pi is when we are at the competition, how will I be able to consistently connect to where I will be streaming the video? Can I give a domain name to the Pi's video stream so that I always can connect?

virtuald
05-01-2016, 22:58
You could use AVAHI, the same multicast DNS technology that's used to find the roborio's DNS name.

Once I get it packaged and on the opkg feed for RobotPy, it should be pretty safe to install without fearing bricking the RoboRIO.