Search code examples
c#opencvreal-timepictureboxemgucv

600 Milliseconds delay in EmguCv real-time video Decoding


I am developing a real-time computer vision application using C#. But I am not able to optimize Emgucv decoding. I have 800-millisecond delay from the ground truth and 600-millisecond delay from the Ip camera provider application AXIS.

How can I optimize the code that I can have at-most 250-milliseconds delay?

Here is code for grabbing an image.

capture1 = new Capture(IpFirstCamTxt.Text);     //create a camera captue from RTSP Stream
capture2 = new Capture(Ip2ndCamTxt.Text);
capture3 = new Capture(Ip3rdCamTxt.Text);
capture4 = new Capture(Ip4thCamTxt.Text);

capture1.Start();
capture2.Start();
capture3.Start();
capture4.Start();
capture1.ImageGrabbed += ProcessFrame1;
capture2.ImageGrabbed += ProcessFrame2;
capture3.ImageGrabbed += ProcessFrame3;
capture4.ImageGrabbed += ProcessFrame4;



private void ProcessFrame1(object sender, EventArgs arg)
{
    _capture.RetrieveBgrFrame().ToBitmap());
    capture1.Retrieve(img1, 3);
    pictureBox1.Image = img1.ToBitmap();
}
private void ProcessFrame2(object sender, EventArgs arg)
{
    capture2.Retrieve(img2, 3);
    pictureBox3.Image = img2.ToBitmap();

}
private void ProcessFrame3(object sender, EventArgs arg)
{
    capture3.Retrieve(img3, 3);
    pictureBox4.Image = img3.ToBitmap();
}
private void ProcessFrame4(object sender, EventArgs arg)
{
    capture4.Retrieve(img4, 3);
    pictureBox5.Image = img4.ToBitmap();
}

Stopwatch results of my application comparing with camera provider application: Stopwatch results of my application comparing with camera provider application


Solution

  • The above-mentioned problem has been solved using one of the real-time RTSP stream capturing library named as LIVE555. I have used it in C++ and shared the memory of images with C#. The delay is reduced up to round about 200 milliseconds only. If anyone wants real-time video streaming then LIVE555 is the best. I will upload the project to my Github.

    Source Real-time RTSP Stream Decoding