Error on ocl::filter2D

asked 2019-06-02 06:26:22 -0600

comar gravatar image

Hi, I'm trying to test ocl::filter2D on openCv 2.4.11, x86 compiled on VS2013:

cv::Mat createKernel(int rowK, int colK, int type, int bn)
{
    int arrSize = rowK*colK;
    float *arraySrc = new float[arrSize];

    if (rowK == 1)
    {
        for (int i = 0; i<arrSize; i++)
        {
            arraySrc[i] = 1.0f / arrSize;
        }
    }
    else
    {
        for (int i = 0; i<arrSize; i++)
        {
            if (i<(arrSize / 2))
                arraySrc[i] = bn*1.0f / arrSize;
            else
                arraySrc[i] = bn*-1.0f / arrSize;
        }
    }
    cv::Mat kernel = cv::Mat(rowK, colK, type, (float*)arraySrc);
    return kernel;
}


int main(int argc, char* argv[])
{       
    cv::Mat frame = cv::imread("myImage.bmp", CV_LOAD_IMAGE_GRAYSCALE);

  // Snap 

    cv::ocl::setDevice(devInfo[0]);        // select device to use

    cv::ocl::oclMat ocl_src(frame);
    cv::ocl::oclMat oclProcessed1;// (frameProcessed1);
    cv::ocl::oclMat oclProcessed2;// (frameProcessed2);

    cv::Mat ker1 = createKernel(kerDim, frame.cols, CV_32FC1, 1);
    cv::Mat ker2 = createKernel(kerDim, frame.cols, CV_32FC1, -1);

    ocl::filter2D(ocl_src, oclProcessed1, -1, ker1);
    ocl::filter2D(ocl_src, oclProcessed2, -1, ker2);
    ocl::finish();
   }

but it gives error: OpenCV Error: Assertion failed (ksize.height > 0 && ksize.width > 0 && ((ksiz eight & 1) == 1) && ((ksize.width & 1) == 1)) in `anonymous-namespace'::norma eROI, file C:\Sviluppo\opencv-2.4.11\modules\ocl\src\filtering.cpp, line 78

The same code works using standard cv::filter2D. Any idea about which problem is occurring? Thank you Marco

edit retag flag offensive close merge delete