Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hangs on creating Capture or grabbing from offline IP-camera #22

Open
cbagpipe opened this issue Apr 27, 2017 · 3 comments
Open

Hangs on creating Capture or grabbing from offline IP-camera #22

cbagpipe opened this issue Apr 27, 2017 · 3 comments

Comments

@cbagpipe
Copy link

cbagpipe commented Apr 27, 2017

Very simple code to reproduce subject. It completely stucks. I can't even kill thread or cancel task whenever it hangs.

Using EmguCV 3.1.0.1 NuGet package

using Emgu.CV;
using System;

namespace OpenCVTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // if camera offline from start, program stucks here.
            var capture = new Capture(@"rtsp://192.168.123.123/");

            // if camera becomes and stays offline mone than 20-30 seconds, program stucks here
            while (capture.Grab())
            {
                Console.Write("grab.");
            }
        }
    }
}
@kolomietsvv
Copy link

kolomietsvv commented Jul 14, 2017

If still relevant. I have Inherited the Capture class (v3.1.0.1 the Capture class still had not been renamed to VideoCapture, version from nuget), and I have overrided the Grab function. That is what I've got.

public class VideoCapture : Capture
    {
        public new event EventHandler ImageGrabbed;

        public event EventHandler GrabFailed;

        public VideoCapture(string inputString) : base(inputString) { }

        [HandleProcessCorruptedStateExceptions]
        public override bool Grab()
        {
            try
            {
                if (_ptr == IntPtr.Zero)
                    return false;

                bool grabbed = cveVideoCaptureGrab(Ptr);

                if (grabbed)
                    ImageGrabbed?.Invoke(this, new EventArgs());
                else
                    GrabFailed?.Invoke(this, new EventArgs());
                return grabbed;
            }
            catch
            {
                Thread.Yield();
                GrabFailed?.Invoke(this, new EventArgs());
                return false;
            }
        }

        /// <summary>
        /// Grab a frame
        /// </summary>
        /// <param name="capture">Video capturing structure</param>
        /// <returns>True on success</returns>
        [DllImport("cvextern", CallingConvention = CvInvoke.CvCallingConvention)]
        [return: MarshalAs(CvInvoke.BoolToIntMarshalType)]
        internal static extern bool cveVideoCaptureGrab(IntPtr capture);
}

Sometimes _capture.GrabFailed += ReconnectCamera works, but sometimes it steps into grub, but doesn't reach the GrabFailed?.Invoke(this, new EventArgs());. And stays somwhere in bool grabbed = cveVideoCaptureGrab(Ptr);

@LingboTang
Copy link

I don't think this problem has been fixed up till now, when I read the source code, there's no exception handling for Grab, Retrieve and QueryFrame. I'm using the *.dll directly, so I can't simply override that one function. It is really inconvenient, please consider fix it right away.

@LingboTang
Copy link

After we get an decoding error like:

h264: cabac decode of qscale diff failed at error decoding

This line:

bool grabbed = CvInvoke.cveVideoCaptureGrab(Ptr);

will always return false because the Ptr will point to null, so cveVideoCaptureGrab will not grab any frames successfully. How I fix this problem right now is every time the decoding error pops up, I'll just restart the capture. But I think EmguCV should handle this problem on your side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants