Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

If you just want to create custom kernels, you just need to create binary Mat:

cv::Mat myker(cv::Mat::zeros(5, 5, CV_8U));
for (int i = 0; i < myker.cols; ++i) myker.ptr< uchar >(i)[2] = 255;

this is an example for a vertical line of 1x5, but you can do what you need. You can use fillPoly for filling the shape if you have a polygon.

I have tested and it seems that the erosion with this line and a rectangle of size (1, 5) is the same. But you can try yourself too (using countNonZeros of the difference between the two Mats)

If you just want to create custom kernels, you just need to create binary Mat:

cv::Mat myker(cv::Mat::zeros(5, 5, CV_8U));
for (int i = 0; i < myker.cols; ++i) myker.ptr< uchar >(i)[2] = 255;

this is an example for a vertical line of 1x5, but you can do what you need. You can use fillPoly for filling the shape if you have a polygon.

I have tested and it seems that the erosion with this line and a rectangle of size (1, 5) is the same. same for some images. But you can try yourself too (using countNonZeros of the difference between the two Mats)


Remark: The 2 kernels do not produce the same results on all the images, so feel free to create your "line" kernel