FRCVision C++ MultiCamera Example with Debug Video Output

We are working with the C++ multiCameraServer with a GRIP pipeline. Within the loop we have a simple wrapper around the generated GRIP pipeline (where grep::InfinteRecharge is an unmodified C++ pipeline generated by GRIP):

class Pipeline : public grip::InfiniteRecharge, cs::CvSource  {
public:
   Pipeline(const wpi::Twine& name, const cs::VideoMode& mode) : cs::CvSource(name, mode) { }

   void Process(cv::Mat& mat) override {
      grip::InfiniteRecharge::Process(mat);
      PutFrame(*GetCvErodeOutput());
   }
};

And then in the main there is some code like:

    SwitchedCameraConfig debugOutput = { "debug", "debug" };
    Pipeline* pipeline = new Pipeline("debug", cameras[0].GetVideoMode());
    auto debugCamera = StartSwitchedCamera(debugOutput);

    if (cameras.size() >= 1) {
        std::thread([&] {
           frc::VisionRunner<Pipeline> runner(cameras[0], pipeline, [&](Pipeline &pipeline) {
                  *snip some contour bounding box code, that writes to network tables

Just trying to add a second network stream that would allow us to watch a masked stream (or any other cv::Mat we wanted to see.

Am I going the wrong direction? (just trying to keep things working with the framework, but not quite sure where to add the output).

Thanks for your time

To create a new stream that you can send OpenCV images to, just call CameraServer::GetInstance().PutVideo(). This creates a MjpegServer and a CvSource and hooks one to the other, and returns the CvSource. I generally recommend using composition over inheritance (e.g. having a member of your Pipeline class be cs::CvSource instead of deriving from it), but if you want to keep your current structure, just change the cs::CvSource() portion of the construction to be cs::CvSource(CameraServer::GetInstance().PutVideo(...)).

You can also create a MjpegServer yourself and hook up a CvSource manually to it using SetSource(), but I recommend using the CameraServer convenience functions as they also publish information about the created stream to NetworkTables so they show up in dashboard camera lists.

Thank you. Moved the camera initialization out of the pipeline completely. Switch it on/off now and have two extra streams when enabled for debugging.

Works great.

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