I’ve been having trouble getting two USB cameras to work with cscore .
I use the following code to enable one camera and it works great:
try:
self.camera_1 = cscore.UsbCamera()
self.camServ = cscore.CameraServer()
self.camServ.addCamera(self.camera_1)
self.camServ.startAutomaticCapture()
print("camera success")
except:
self.camera = None
I then tried the following code for two cameras , but to no avail:
try:
self.camera_1 = cscore.UsbCamera("cam0", 0)
self.camera_1 = cscore.UsbCamera("cam1", 1)
self.camServ = cscore.CameraServer()
self.camServ.addCamera(self.camera_1)
self.camServ.addCamera(self.camera_2)
self.camServ.startAutomaticCapture()
print("camera success")
except:
self.camera = None
Am I doing this correctly? Have any of you encountered this problem? Thanks in advance.
loveshark:
I’ve been having trouble getting two USB cameras to work with cscore .
I use the following code to enable one camera and it works great:
try:
self.camera_1 = cscore.UsbCamera()
self.camServ = cscore.CameraServer()
self.camServ.addCamera(self.camera_1)
self.camServ.startAutomaticCapture()
print("camera success")
except:
self.camera = None
I then tried the following code for two cameras , but to no avail:
try:
self.camera_1 = cscore.UsbCamera("cam0", 0)
self.camera_1 = cscore.UsbCamera("cam1", 1)
self.camServ = cscore.CameraServer()
self.camServ.addCamera(self.camera_1)
self.camServ.addCamera(self.camera_2)
self.camServ.startAutomaticCapture()
print("camera success")
except:
self.camera = None
Am I doing this correctly? Have any of you encountered this problem? Thanks in advance.
What is the error message you’re getting? Generally, you don’t want to swallow exceptions, as they will often help you figure out what’s going on.
Also, I think you don’t need to call startAutomaticCapture if you’re creating the cameras/feeds already.
Here is a screenshot of my terminal.
http://i.imgur.com/lF5PZjz.png
It seems to keep to keep repeating the following lines
http://i.imgur.com/oDFNslR.png
Did you install mjpg-streamer at some point? It appears that something else is using your camera. May want to reboot the RoboRIO…
We restarted the roboRio and have the same problem. We have never installed jpeg streamer, should we?
Also the second camera wasn’t plugged in properly, we reconnected the cameras and now have the following errors:
https://i.imgur.com/qZMtDPh.png
loveshark:
We restarted the roboRio and have the same problem. We have never installed jpeg streamer, should we?
Also the second camera wasn’t plugged in properly, we reconnected the cameras and now have the following errors:
https://i.imgur.com/qZMtDPh.png
I would not install mjpg-streamer, it will cause issues.
I’m pretty sure I’ve tried two cameras before. I’ll try it out again tonight and see what I find. It’s strange that you’re having issues with camera 0, and not camera 1. You might try changing the FPS.
The code for two cameras is way simpler than what you were trying to do:
def main():
cs = CameraServer.getInstance()
cs.enableLogging()
usb1 = cs.startAutomaticCapture(dev=0)
usb2 = cs.startAutomaticCapture(dev=1)
cs.waitForever()
I think it should be a bug to try to open the same device twice… I’ll look into it, it should give you a more sensible error message.
virtuald:
The code for two cameras is way simpler than what you were trying to do:
def main():
cs = CameraServer.getInstance()
cs.enableLogging()
usb1 = cs.startAutomaticCapture(dev=0)
usb2 = cs.startAutomaticCapture(dev=1)
cs.waitForever()
I think it should be a bug to try to open the same device twice… I’ll look into it, it should give you a more sensible error message.
That code works, thanks a lot!