Post-processing HTTP video source (from Chameleon Vision) in Shuffleboard

We are using Chameleon Vision running on Raspberry Pi 4 B to capture video and track the vision target. The resulting video stream is available in Shuffleboard via the CameraServer and is also directly accessible in a browser without any problems.

Question: how do we get hold of this video stream and modify it with OpenCV calls?

We can find plenty of Java examples that open a local USB camera (USB stream shows just fine in Shuffleboard):

  UsbCamera camera = CameraServer.getInstance().startAutomaticCapture();
  camera.setResolution(640, 480);

  CvSink cvSink = CameraServer.getInstance().getVideo();
  CvSource outputStream = CameraServer.getInstance().putVideo("Modified", 640, 480);

  Mat source = new Mat();

  while(!Thread.interrupted()) {
      cvSink.grabFrame(source);
      Imgproc.circle(source, new Point(100,100), 10, new Scalar(255,255,0));
      outputStream.putFrame(source);
  }

What we need is to open an HTTP stream instead. You would think this will do the trick, but … no sign of the feed in Shuffleboard CameraServer:

  HttpCamera chameleonFeed = new HttpCamera("chameleon",
      "http://raspberrypi.local:1181/?action=stream,mjpg:http://10.0.0.225", HttpCameraKind.kMJPGStreamer);
  MjpegServer camera = CameraServer.getInstance().startAutomaticCapture(chameleonFeed);

Thoughts?

That URL does not look correct. It should end after the “action=stream” part; the part beginning with “,mjpg:” is another URL. You might also try using CameraServer.addAxisCamera with just the IP address (the Axis camera uses the same URL scheme).

Also, where is this code running? On the Rio? On a desktop application? It seems non-ideal to have the Rio do this extra processing work (decompress image, do OpenCV, recompress image) when you have a Pi.

Thanks for the quick reply. This is running on a desktop as a part of our targeting system during testing (it’s useful to see where the ball is in the frame). But, good point about Rio–we would not want to run it this way during the game.

You are also right about the URL. But correcting it did not do the trick. Neither did using Axis camera …

AxisCamera camera = CameraServer.getInstance().addAxisCamera("AxisCam", "http://raspberrypi.local:1181/?action=stream");
camera.setResolution(640, 480);
CvSink cvSink = CameraServer.getInstance().getVideo("AxisCam");
CvSource outputStream = CameraServer.getInstance().putVideo("Modified", 640, 480);

“AxisCam” shows up in the CameraServer list on Shuffleboard, but displays as a black solid square (no video, wrong size) …

-rg

If you use AxisCamera you shouldn’t pass a URL, just the IP address or hostname (eg “raspberrypi.local”). AxisCamera internally builds the correct URL.

Again, thanks for quick help.

Using “raspberrypi.local” still produces a black square in Shuffleboard. The source filed shown in the left panel will say: “http://raspberrypi.local/mjpg/video.mjpg” while the direct (working) Chameleon stream shows: “http://raspberrypi.local:1181/?action=stream,.…”

-rg

Oh, right, AxisCamera is port 80. Sorry, forgot about that detail. Using HttpCamera with a url that consists of just "http://raspberrypi.local:1181/?action=stream" should work.

Axis approach did not work, but applying your suggestion to HttpCamera did! Here’s the solution:

HttpCamera chameleonFeed = new HttpCamera("chameleon", "http://raspberrypi.local:1181/?action=stream", HttpCameraKind.kMJPGStreamer);

MjpegServer camera = CameraServer.getInstance().startAutomaticCapture(chameleonFeed);

CvSink cvSink = CameraServer.getInstance().getVideo("chameleon");

Many thanks, Peter.

1 Like

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