Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
901 views
in Technique[技术] by (71.8m points)

c# - 无法使用EMGU CV连续从RTSP流中获取图像(Unable to use EMGU CV to grab images from RTSP stream continuously)

I am trying to obtain images from an RTSP Stream from an IP Camera using a C# Windows Forms application.

(我正在尝试使用C#Windows Forms应用程序从IP摄像机从RTSP流中获取图像。)

I am using EMGU CV to capture stream continuously but the RTSP Steam stops after a few seconds and then the imageGrabbedEvent never fires.

(我正在使用EMGU CV连续捕获流,但是RTSP Steam在几秒钟后停止,然后imageGrabbedEvent永不触发。)

My purpose is simple: to get every frame from the camera and analyze it.

(我的目的很简单:从相机中获取每一帧并进行分析。)

I am using a HIKVision IP Camera(DS-2CD2683G1-IZ) with an IP Address of 192.168.1.64 streaming RTSP on port 554 (which is the default IP address and Port number for many Hikvision IP Cameras)

(我在端口554上使用IP地址为192.168.1.64流式RTSP的HIKVision IP摄像机(DS-2CD2683G1-IZ)(这是许多Hikvision IP摄像机的默认IP地址和端口号))

DateTime LastTimeImageGrabReinitialised = new DateTime();


public void InitializeCameraEMGUStream()
        {
            //added a datetime to the url as recommended by another answer but it didnt help.
            VideoCapture myVideoCapture = new VideoCapture("rtsp://admin:[email protected]:554/ch1/main/av_stream?"+DateTime.Now.ToString());
            myVideoCapture.ImageGrabbed += imageGrabbedEvent;
            myVideoCapture.Start();

            LastTimeImageGrabReinitialised = DateTime.Now;

        }

private void imageGrabbedEvent(object sender, EventArgs e)
        {
            lastTimeImageGrabbed = DateTime.Now;
            try
            {
                Mat m = new Mat();
                myVideoCapture.Retrieve(m);
                LatestAcquiredImage = m.ToImage<Bgr, byte>().Bitmap;
                pictureBox.Image = m.ToImage<Bgr, byte>().Bitmap;
                imgEntrada = m.ToImage<Bgr, byte>();
            }
            catch (Exception Ex)
            {



            }

            //I tried adding some logic to reinitialize the stream after a few hundred milliseconds, 
            //but it seems the reinitialization takes a while to obtain a clear image and many frames cannot be read.
            if((DateTime.Now- LastTimeImageGrabReinitialised).TotalMilliseconds>200)
            {

                myVideoCapture.Start();
                LastTimeImageGrabReinitialised = DateTime.Now;
            }

        }


I have gone through a couple of answers available online but cannot find a definitive way to keep the stream alive.

(我已经在网上找到了一些答案,但是找不到一种确定的方法来保持视频流的生命。)

I would really appreciate any help in this regard.

(在这方面的任何帮助,我将不胜感激。)

FYI: What I have already tried:

(仅供参考:我已经尝试过:)

  1. I tried reinitializing the VideoCapture every some time but it is slow and many initial frames are noisy/unclear images.

    (我尝试每隔一段时间重新初始化VideoCapture,但是它很慢,许多初始帧都是嘈杂/不清楚的图像。)

  2. I already tried using VLC.Dotnet to run the RTSP steam, the stream works perfectly fine but to grab an image and convert it to and Image is very slow, primarily because VLCControl.TakeSnapshot() saves the file on disk.

    (我已经尝试过使用VLC.Dotnet运行RTSP蒸汽,该流工作正常,但要抓取图像并将其转换为图像,并且图像非常慢,这主要是因为VLCControl.TakeSnapshot()将文件保存在磁盘上。)

    At the best this consumes more then 500milliseconds and many frames are lost during that time.

    (最好情况下,这会耗费超过500毫秒的时间,并且在此期间会丢失许多帧。)

  3. I additionally also tried using RTSPClientSharp, while using that, the imageGrabbed event fires regularly but I but was unable to get to display a decoded image.

    (另外,我还尝试使用RTSPClientSharp,但使用该事件时,imageGrabbed事件会定期触发,但我无法显示解码后的图像。)

  4. I tried getting images from the camera using HTTP, however each image takes more then 600ms to arrive and the camera wont accept any other connection requests in the meanwhile, hence many frames are again lost.

    (我尝试使用HTTP从摄像机获取图像,但是每个图像要花600毫秒以上的时间才能到达,并且摄像机在此期间不接受任何其他连接请求,因此很多帧再次丢失。)

  ask by Nouman Qaiser translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...