I’d like to initialize a 3 by 3 cross-shaped kernel matrix and use it to dilate an image in OpenCV4Android. In native C++ OpenCV, you’d 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 treated like an array, and Java has no << operator. There seems to be an OpenCV function called cvCreateStructuringElementEx which initializes Mats for use as kernels, but I can’t find this function in OpenCV4Android.
Thanks so much.
I have never tried this but check if it works, at least this is the OpenCV4Android way to set a Structuring Element:
Also, check out copyTo() method, it can receive a Mask: