CameraServer port

I am going to run two separate processes on a Jetson Nano, one for object detection and another for driver cameras. I have this working well, except I cannot figure out how to set the MjpegServer port and get meaningful entries in the CameraPublisher network table. I need to use two ports since I want two different streams from separate processes.

This code gives me the desired camera result. I have one camera server, on port 1182, that I can then switch using the server.setSource() method. I can open the camera server in a browser on port 1182 and it is named “DriverCombined”. However, in Shuffleboard I get two entries under “CameraServer”; “DriverCam0” and “DriverCam1”. DriverCam0 can be dragged to shuffleboard and it displays my “DriverCombined” stream.

cs = CameraServer.getInstance()
cs.enableLogging()

usbCam0 = cscore.UsbCamera("DriverCam0", args.camera0_url)
usbCam0.setPixelFormat(cscore.VideoMode.PixelFormat.kMJPEG)
usbCam0.setResolution(args.width, args.height)
usbCam0.setFPS(args.rate)
usbCam0.setConnectionStrategy(cscore.VideoSource.ConnectionStrategy.kKeepOpen)

usbCam1 = cscore.UsbCamera("DriverCam1", args.camera1_url)
usbCam1.setPixelFormat(cscore.VideoMode.PixelFormat.kMJPEG)
usbCam1.setResolution(args.width, args.height)
usbCam1.setFPS(args.rate)
usbCam1.setConnectionStrategy(cscore.VideoSource.ConnectionStrategy.kKeepOpen)

server = cs.addServer(name="DriverCombined", port=args.port)
server.setSource(usbCam0)

server.setCompression(args.stream_compression)
server.setFPS(args.rate)
server.setResolution(args.width, args.height)

The CameraServer API does too much internally and I’m struggling to get it to do anything other than the exact use case it was written for - automatically capturing from a USB camera and streaming to port 1181.

I tried using the startAutomaticaCapture method, but I cannot find any way to set the port, it’s always 1181.

For advanced use cases, you don’t need to use the CameraServer class at all, and can instead just publish camera information to NT yourself. Replace the cs.addServer call with constructing MjpegServer. Then publish to NetworkTables /CameraPublisher/DriverCombined/streams with a string array, where each string is mjpg:http://<IP or host>:<port>/?action=stream

Thanks @Peter_Johnson. I had tried constructing the MjpegServer myself, but I couldn’t get it to show up on Shuffleboard. I’ll try adding the NT entry.

I have not been able to find much documentation. All of the docs just say to use ‘startAutomaticCapture’, otherwise your kind of on your own. The only way I found to discover how Shuffleboard interacts with CameraServer / CameraPublishers is by reverse engineering the code.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.