OpenCV for Android - matrix initialization

I would like to initialize the 3 × 3 kernel matrix and use it to expand the image in OpenCV4Android. In native C ++ OpenCV, you would do:

Mat kernel = (Mat_<int>(3,3) << 0,1,0,1,1,1,0,1,0); dilate(image, image, kernel); 

but how can I do the equivalent of the first line in Java? A mat cannot be considered as an array, and Java does not have a <<<operator. There seems to be an OpenCV function cvCreateStructuringElementEx that initializes Mats for use as kernels, but I cannot find this function in OpenCV4Android.

Thank you very much.

+4
source share
1 answer

I have never tried this, but I check to see if it works, at least this is the OpenCV4Android way to set the structuring element:

 Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 3)); 

Also check the copyTo () method, it can get the mask:

 src_mat.copyTo(dst_mat, mask); 
+3
source

Source: https://habr.com/ru/post/1433179/


All Articles