What's causing the assertion fail in cv::ocl::convertFromImage
I'm getting an assertion fail in the last assertion in ocl.cpp (line 5466?),
OpenCV Error: Assertion failed (clEnqueueCopyImageToBuffer(q, clImage, clBuffer, src_origin, region, offset, 0, NULL, NULL) == CL_SUCCESS) in convertFromImage, file /home/xxxxx/opencv-3.0.0/modules/core/src/ocl.cpp, line 5466
This line:
CV_Assert(clEnqueueCopyImageToBuffer(q, clImage, clBuffer, src_origin, region, offset, 0, NULL, NULL) == CL_SUCCESS);
which I would have thought it wouldn't have made it all the way through the function and then fault there. Here is the code, I'm probably mixing up the library notation somehow.
int main()
{
cv::Mat mat(480, 640, CV_32FC4);
mat.setTo(cv::Scalar(0,1,1,0));
cv::imshow("CVforCLimage", mat);
cv::waitKey(0);
cl_platform_id platform;
cl_device_id device;
cl_context context;
cl_int err;
clGetPlatformIDs(1, &platform, NULL);
clGetDeviceIDs(platform, CL_DEVICE_TYPE_GPU, 1, &device, NULL);
context = clCreateContext(NULL, 1, &device, NULL, NULL, &err);
cl_mem IDKmem;
cl_image_format tif_format;
tif_format.image_channel_order = CL_RGBA;
tif_format.image_channel_data_type = CL_FLOAT;
IDKmem = clCreateImage2D(context, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR,&tif_format,mat.cols, mat.rows, 0,mat.data,&err);
cv::UMat Umat;
cv::ocl::convertFromImage(IDKmem, Umat);
cv::imshow("CVforCLimage", Umat);
cv::waitKey(0);
return 0;
}
The function convertFromImage is causing the problem, I tried to make it as basic as I could to try and understand the numenclautre. Thanks!
I'm not a guru at all of opencl but you are a creatiing an opencl context and after you ask opencv to use opencl. But I think there is already a context in opencv
Instead of creating your own context can you use opencv context.
I'll give it a shot, thanks! The one problem I see (and yes, it is a problem of my own doing), is that I have combined the C++ of OpenCV with the C of OpenCL. Granted I can use the C++ wrapper for OpenCL but I have not gotten that smart yet! Thanks!
I tried it this way and got a segmentation fault instead of an assertion fail, so I assume I can not use the OpenCL C++ to create the cl::image2D
I also tried:
and I got "no matching function for call to cl::Image2d::Image2D(cv::ocl::Context&, ... error