Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

(u->refcount == 0) in deallocate

Hi,

I am having an issue that only occurs on Linux (arm) on my Raspberry Pi 3b. It works fine on windows.

I am trying to read a video file using this loop:

while (videoCapture.isOpened()) {

    DebugWrite("Start Grabbing Frame from VIDEO stream.", "ImageGrabber::RunGrabber");
    _shouldStop.mx.lock();
    if (_shouldStop.stop) {
        break;
    }
    _shouldStop.mx.unlock();

    DebugWrite("Initiating MAT", "ImageGrabber::RunGrabber");
    cv::Mat frame;

    DebugWrite("Finished Initiating MAT, reading frame!", "ImageGrabber::RunGrabber");
    if (videoCapture.read(frame)) {
        DebugWrite("Frame written.", "ImageGrabber::RunGrabber");
        if (cv::waitKey(30) >= 0 || frame.empty()) break;

        DebugWrite("Copying frame to UMAT.", "ImageGrabber::RunGrabber");
        _frameBuffer.mx.lock();
        frame.copyTo(*_frameBuffer.writeFrame);
        _frameBuffer.notempty = true;
        DebugWrite("Frame copied to UMAT.", "ImageGrabber::RunGrabber");
        _frameBuffer.mx.unlock();

        DebugWrite("Videocapture (" + _imageSource.source + ").", "ImageGrabber::RunGrabber", frame);
    }
    else {
        DebugWrite("Could not read video.", "ImageGrabber::RunGrabber");
        break;
    }


}

It read the first frame fine. But when I want to read the second frame from the video file it throws this error:

image description

As can be seen from the debug messages, the error happens on the line:

if (videoCapture.read(frame))

Since it happens here, it feels like something that is out of my control.

This code runs fine on my windows machine. Another peculiar thing is the fact that it tries to open the "OpenCL runtime"? As far as I know, opencl is not supported on the raspberry pi. As can be seen, this runs in a seperate thread and the frame is accessed in another thread, but protected by mutexes. In the other thread a pointer swap is done to prevent the necessity to copy the frame.

I have no clue if I am doing something wrong or that something underwater (with opencv) is going wrong. If someone knows of a similar issue or can give me pointers (no pun intended ;) ) to a solution, I would be very glad.

Thanks in advance!

(u->refcount == 0) in deallocate

Hi,

I am having an issue that only occurs on Linux (arm) on my Raspberry Pi 3b. It works fine on windows.

I am trying to read a video file using this loop:

while (videoCapture.isOpened()) {

    DebugWrite("Start Grabbing Frame from VIDEO stream.", "ImageGrabber::RunGrabber");
    _shouldStop.mx.lock();
    if (_shouldStop.stop) {
        break;
    }
    _shouldStop.mx.unlock();

    DebugWrite("Initiating MAT", "ImageGrabber::RunGrabber");
    cv::Mat frame;

    DebugWrite("Finished Initiating MAT, reading frame!", "ImageGrabber::RunGrabber");
    if (videoCapture.read(frame)) {
        DebugWrite("Frame written.", "ImageGrabber::RunGrabber");
        if (cv::waitKey(30) >= 0 || frame.empty()) break;

        DebugWrite("Copying frame to UMAT.", "ImageGrabber::RunGrabber");
        _frameBuffer.mx.lock();
        frame.copyTo(*_frameBuffer.writeFrame);
        _frameBuffer.notempty = true;
        DebugWrite("Frame copied to UMAT.", "ImageGrabber::RunGrabber");
        _frameBuffer.mx.unlock();

        DebugWrite("Videocapture (" + _imageSource.source + ").", "ImageGrabber::RunGrabber", frame);
    }
    else {
        DebugWrite("Could not read video.", "ImageGrabber::RunGrabber");
        break;
    }


}

It read the first frame fine. But when I want to read the second frame from the video file it throws this error:

image description

SmartPause::DetectionThread | Not Stopping Detection Thread
SmartPause::DetectionThread | Retreiving Frame
SmartPause::DetectionThread | Not Stopping Detection Thread
ImageGrabber::RunGrabber | Copying frame to UMAT.SmartPause::DetectionThread | Retreiving Frame

SmartPause::DetectionThread | Not Stopping Detection Thread
SmartPause::DetectionThread | Retreiving Frame
[ INFO:0] Initialize OpenCL runtime...
ImageGrabber::RunGrabber | Frame copied to UMAT.
ImageGrabber::RunGrabber | Videocapture (/home/pi/test.mp4).
SmartPause::DetectionThread | Reading frame from buf0
SmartPause::DetectionThread | Image To Process
ImagePreProcessor::PerformPreProcessing | Start Image PreProcessing
ImageGrabber::RunGrabber | Start Grabbing Frame from VIDEO stream.
ImageGrabber::RunGrabber | Initiating MAT
ImageGrabber::RunGrabber | Finished Initiating MAT, reading frame!
OpenCV(4.0.0-dev) Error: Assertion failed (u->refcount == 0) in deallocate, file /home/pi/opencv/modules/core/src/matrix.cpp, line 169
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.0.0-dev) /home/pi/opencv/modules/core/src/matrix.cpp:169: error: (-215:Assertion failed) u->refcount == 0 in function 'deallocate'

Aborted

As can be seen from the debug messages, the error happens on the line:

if (videoCapture.read(frame))

Since it happens here, it feels like something that is out of my control.

This code runs fine on my windows machine. Another peculiar thing is the fact that it tries to open the "OpenCL runtime"? As far as I know, opencl is not supported on the raspberry pi. As can be seen, this runs in a seperate thread and the frame is accessed in another thread, but protected by mutexes. In the other thread a pointer swap is done to prevent the necessity to copy the frame.

I have no clue if I am doing something wrong or that something underwater (with opencv) is going wrong. If someone knows of a similar issue or can give me pointers (no pun intended ;) ) to a solution, I would be very glad.

Thanks in advance!