Exception deep inside OpenCV code

asked 2015-07-16 19:08:40 -0500

unxnut gravatar image

I am writing code to perform background subtraction. The relevant part of the code is:

cv::Mat     fg_mask;                    // Foreground mask generated by MOG2 method
cv::Ptr<cv::BackgroundSubtractor> mog2; // MOG2 background subtractor
mog2 = cv::createBackgroundSubtractorMOG2();

//**********************************************************************
// Start processing the video

while ( video.read ( frame ) )
{
#ifdef _DEBUG
    frame_num++;
    std::cout << frame_num << '\n';
#endif

    cv::Mat gray;
    cv::cvtColor ( frame, gray, cv::COLOR_BGR2GRAY );
    mog2->apply ( gray, fg_mask ); 
    ...
}

As I start to execute the code, I get an exception thrown from inside ocl.cpp from the statement:

CV_OclDbgAssert(clEnqueueUnmapMemObject(q, (cl_mem)u->handle, data, 0, 0, 0) == CL_SUCCESS);

saying

-       cstr_   0x00ed9d04 "..\..\opencv\sources\modules\core\src\ocl.cpp:4446: error: (-215) clEnqueueUnmapMemObject_pfn(q, (cl_mem)u->handle, data, 0, 0, 0) == 0 in function cv::ocl::OpenCLAllocator::deallocate"

I am able to run this in a standalone application but the integration is causing me headaches. The exception is thrown from a deallocation function which is weird. Just wondering if anyone has come across such error.

edit retag flag offensive close merge delete

Comments

there seems to be a related issue : http://code.opencv.org/issues/4277#no...

berak gravatar imageberak ( 2015-07-17 00:07:29 -0500 )edit
1

Thanks @berak. I may add that when I changed from MOG2 to KNN, the app moved forward but is very slow. I am running on Windows 7, VS 10, OpenCV 3.0Gold. It seems to be a memory corruption issue but I have no idea on how to debug it.

unxnut gravatar imageunxnut ( 2015-07-17 10:19:48 -0500 )edit

Update: I recompiled OpenCV disabling OpenCL. That fixed it and I am a slightly happier camper. I'll still like to use OpenCL functionality.

unxnut gravatar imageunxnut ( 2015-07-17 13:36:44 -0500 )edit