I try translate, and I try this:
Mat markers = new Mat(rgba.size(),CvType.CV_8UC3, new Scalar(-1));
markers.submat(new Rect(0,0,rgba.cols(), 5)).setTo(new Scalar(1,1,1));
markers.submat(new Rect(0,rgba.rows()-5,rgba.cols(), 5)).setTo(new Scalar(1,1,1));
markers.submat(new Rect(0,0,5, rgba.rows())).setTo(new Scalar(1,1,1));
markers.submat(new Rect(rgba.cols()-5,0,5, rgba.rows())).setTo(new Scalar(1,1,1));
int centreW = rgba.cols()/4;
int centreH = rgba.rows()/4;
markers.submat(new Rect((rgba.cols()/2)-(centreW/2), (rgba.rows()/2)-(centreH/2), centreW, centreH)).setTo(new Scalar(2,2,2));
markers.convertTo(markers, Imgproc.COLOR_BGR2GRAY);
But now I have that error with opencv:
E/cv::error(): OpenCV(3.4.11) Error: Assertion failed (src.type() == CV_8UC3 && dst.type() == CV_32SC1) in void cv::watershed(cv::InputArray, cv::InputOutputArray), file /build/3_4_pack-android/opencv/modules/imgproc/src/segmentation.cpp, line 161
I change type in that part, but it don’t work or not change correctly:
class WatershedSegmenter {
public Mat markers=new Mat();
public void setMarkers(Mat markerImage)
{
markerImage.convertTo(markers, CvType.CV_32SC1);
}
public Mat process(Mat image)
{
image.convertTo(image, CvType.CV_8UC3);
markers.convertTo(markers,CvType.CV_32SC1);
Imgproc.watershed(image,markers);
//Log.i(TAG, "LLEGA AQUI");
markers.convertTo(markers,CvType.CV_8UC3);
return markers;
}
};
Any help?