Need to compress OpenCV generated image being served to ShuffleBoard

Our team generates an OpenCV image and sends it to the ShuffleBoard this way:

outputStream = CameraServer.getInstance().putVideo("OperatorImage", 640, 45);

Map<String, Object> cameraWidgetProperties = new HashMap<String, Object>();
cameraWidgetProperties.put("Show crosshair", false);
cameraWidgetProperties.put("Show controls", false);

Main.cameraTab.add("High Power Port Alignment", mjpegServer
    .withWidget(BuiltInWidgets.kCameraStream)
    .withProperties(cameraWidgetProperties)
    .withSize(12, 1)
    .withPosition(20, 0);

Shuffleboard.update();

outputStream.putFrame(mat);

The image shows perfectly on the ShuffleBoard but the simplest, small image consumes a huge amount of bandwidth.

We can’t find a way to compress CameraServer objects. (Showing the controls on the ShuffleBoard does allow changing the compression/quality but that is not automatic.)

Using the MjpegServer opens up many settable parameters including quality but the image won’t show in ShuffleBoard.

Using this instead of CameraServer:

CvSource outputStream = new CvSource("OperatorImage", VideoMode.PixelFormat.kMJPEG, 640, 45, 30);
MjpegServer mjpegServer = new MjpegServer("serve_OperatorImage", 1186);
mjpegServer.setCompression(50);
mjpegServer.setSource(outputStream);

does compress the image but it can’t be displayed in ShuffleBoard.

Is there a way to compress automatically (programatically not manually) an OpenCV image on the ShuffleBoard?

CameraServer.putVideo() creates a CvSource and then calls startAutomaticCapture(source), which returns a MjpegServer.

So instead of outputStream = CameraServer.getInstance().putVideo("OperatorImage", 640, 45);

you can do:

CvSource outputStream = new CvSource("OperatorImage", VideoMode.PixelFormat.kMJPEG, 640, 45, 30);
MjpegServer mjpegServer = CameraServer.getInstance().startAutomaticCapture(outputStream);

And then manipulate mjpegServer as you see fit.

The CameraServer classes add information about the stream to NetworkTables, while the lower level cscore classes do not.

Thank you very much - it worked perfectly to reduce bps by 90%. We were surprised to see width, height, fps on the CvSource didn’t carry through to the MjpegServer. It was easy to correct with seemingly duplicate server sets once we figured out why the image was still large with high frame rate.

The CvSource width/height/fps is totally notional at present. It’s really the resolution of the images you provide and how frequently you call putFrame() that determines the width/height/fps; CvSource doesn’t do any internal limiting or scaling.

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