OpenCV UMat with cv::morphologyEx cannot use small kernel

Viewed 30

Environments:

  • OS: Ubuntu 20.04 LTS
  • OpenCV version: 4.4.0
  • OpenCL version: OpenCL 3.0 NEO
  • Device name: Intel(R) Iris(R) Xe Graphics

I test the following code with cv::UMat:

#include <opencv2/opencv.hpp>

int main()
{
    std::string img_f = "...";

    cv::UMat gray = cv::imread(img_f, 0).getUMat(cv::ACCESS_READ);

    cv::UMat thresh;
    cv::adaptiveThreshold(gray, thresh, 255, cv::ADAPTIVE_THRESH_MEAN_C,
        cv::THRESH_BINARY, 21, 0);

    cv::UMat opening;
    cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3, 3));
    cv::morphologyEx(thresh, opening, cv::MORPH_OPEN, kernel);

    cv::imwrite("res.png", opening);
}

But some errors occurred at run time:

OpenCL program build log: imgproc/morph3x3
Status -6: CL_OUT_OF_HOST_MEMORY
-D PROCESS_ELEM_=PROCESS(0,0)PROCESS(0,1)PROCESS(0,2)PROCESS(1,0)PROCESS(1,1)PROCESS(1,2)PROCESS(2,0)PROCESS(2,1)PROCESS(2,2) -D OP_ERODE -D INTEL_DEVICE

OpenCL program build log: imgproc/filterSmall
Status -6: CL_OUT_OF_HOST_MEMORY
-D cn=1 -D ANCHOR_X=1 -D ANCHOR_Y=1 -D KERNEL_SIZE_X=3 -D KERNEL_SIZE_Y=3 -D PX_LOAD_VEC_SIZE=4 -D PX_LOAD_NUM_PX=4 -D DEPTH_0 -D PX_PER_WI_X=8 -D PX_PER_WI_Y=2 -D PRIV_DATA_WIDTH=12 -D BORDER_CONSTANT -D NO_BORDER_ISOLATED -D PX_LOAD_X_ITERATIONS=3 -D PX_LOAD_Y_ITERATIONS=4 -D srcT=uchar -D srcT1=uchar -D dstT=srcT -D dstT1=srcT1 -D WT=srcT -D WT1=srcT1 -D convertToWT=noconvert -D convertToDstT=noconvert -D PX_LOAD_FLOAT_VEC_CONV=convert_uchar4 -D PROCESS_ELEM_=PROCESS(0,0)PROCESS(0,1)PROCESS(0,2)PROCESS(1,0)PROCESS(1,1)PROCESS(1,2)PROCESS(2,0)PROCESS(2,1)PROCESS(2,2) -D OP_ERODE -D INTEL_DEVICE

OpenCL program build log: imgproc/morph
Status -6: CL_OUT_OF_HOST_MEMORY
-D RADIUSX=1 -D RADIUSY=1 -D LSIZE0=16 -D LSIZE1=16 -D OP_ERODE -D PROCESS_ELEMS=PROCESS(0,0)PROCESS(0,1)PROCESS(0,2)PROCESS(1,0)PROCESS(1,1)PROCESS(1,2)PROCESS(2,0)PROCESS(2,1)PROCESS(2,2) -D T=uchar -D DEPTH_0 -D cn=1 -D T1=uchar -D convertToWT=convert_float -D convertToT=convert_uchar_sat_rte -D ST=uchar -D INTEL_DEVICE

If I change the kernel size of cv::morphologyEx bigger, i.e.

cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(11, 11));

It can work.

Why does cv::morphologyEx with UMat have such limitation?

0 Answers
Related