anju
anju

Reputation: 1

C#: AccessViolationException from EmguCV when trying to retrieve frames

I am trying to show live streams from 3 different cameras using EmguCV library. The cameras are connected using VideoCapture class by passing corresponding index to the constructor.

VideoCapture _capture1 = new VideoCapture(0);
VideoCapture _capture2 = new VideoCapture(1);
VideoCapture _capture3 = new VideoCapture(2);

Each instance subscribes to the "ImageGrabbed" event and try to retrieve frame in the event handler.

_capture1.ImageGrabbed += ProcessFrame;

EventHandler:

    private void ProcessFrame(object sender, EventArgs arg)
    {
        if (_capture1!= null && _capture1.Ptr != IntPtr.Zero)
        {
            Mat _frame = new Mat();
            _capture1.Retrieve(_frame, 0);
        }
    }

But occasionally, the _capture.Retrieve() method gives AccessViolationException.

Exception Details:

System.AccessViolationException was unhandled. Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Anybody could explain what can cause this exception?

Upvotes: 0

Views: 635

Answers (1)

Paltr
Paltr

Reputation: 125

I solved it by passing VideoCapture.API.DShow into VideoCapture's constructor instead of using default VideoCapture.API.Any value.

Upvotes: 0

Related Questions