1

I'm just not having any luck whatsoever with this. I'm calling OpenCvSharp.VideoCapture("udp://0.0.0.0:11111") to try to read a video stream. This does not work, and the documentation seems like it doesnt support streaming.

I've also tried (without success) trying to grab images using OpenCvSharp, but i've no idea how to do that. Documentation for it doesn't show any indication this is possible as well.

The snippet for this is here:

        var vc = new OpenCvSharp.VideoCapture("udp://0.0.0.0:11111");

        if (!vc.IsOpened())
        {
            vc.Open("udp://0.0.0.0:11111");
        }

        while (true)
        {
            var matImage = new OpenCvSharp.Mat();
            if (vc.Read(matImage))
            {
                try
                {
                    var bmp = OpenCvSharp.Extensions.BitmapConverter.ToBitmap(matImage);
                    using (var ms = new MemoryStream())
                    {
                        var bmpImg = new BitmapImage();
                        bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                        bmpImg.StreamSource = ms;
                        this.videoFrameImage.Background = new ImageBrush(bmpImg);
                        this.isReadingVideoStream = true;
                    }
                }
                catch
                {
                    // just swallow exception
                }
            }
        }

Before trying OpenCvSharp (which seemed extremely promising), I tried using ffmpeg with mild/partial success. I was able to extra a frame from the real-time streaming video and save it to a file. Unfortunately, the behavior was not consistent. Sometimes it saves images, sometimes it doesn't. And when it does save images it's usually just a handful (even though the video is constantly being streamed).

The command line for this is here:

ffmpeg.exe -i udp://0.0.0.0:11111 -ss 00:00:01 -vframes 1 -q:v 1 -y filename.jpg

I may go back to trying again with ffmpeg as im getting absolutely nowhere with OpenCvSharp. Wondering if anybody out there has been successfully implementing with either one of these (or another way)?

* Update *

I found a set of Nuget packages which does indicate support for streaming video. The nugets are:

  • OpenCvSharp4
  • OpenCvSharp4.Windows
  • OpenCvSharp4.runtime.win

But now i am currently facing a run-time error:

Method not found: 'Void OpenCvSharp.VideoCapture..ctor(System.String, OpenCvSharp.VideoCaptureAPIs)'.

Incidentally, i just raised this issue:

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140

0 Answers0