Hi Samuel,
Please see my code below
public static void main(String[] args) throws IOException {
String file = "C:\\Users\\OpenCV\\1.jpg";
Mat image = load(new File(file), IMREAD_COLOR);
String maskFile = "C:\\Users\\OpenCV\\1_mask.jpg";
Mat maskimage = load(new File(maskFile), IMREAD_GRAYSCALE);
show(toMat8U(image), "original");
int iterCount = 5;
int mode = GC_INIT_WITH_MASK;
// Need to allocate arrays for temporary data
Mat bgdModel = new Mat();
Mat fgdModel = new Mat();
// GrabCut segmentation
grabCut(image, maskimage, new Rect(), bgdModel, fgdModel, iterCount, mode);
show(toMat8U(image), "Result foreground mask");
}
I am getting error as
Exception in thread "main" java.lang.RuntimeException: OpenCV(4.1.2) C:\projects\javacpp-presets\opencv\cppbuild\windows-x86_64\opencv-4.1.2\modules\imgproc\src\grabcut.cpp:344: error: (-5:Bad argument) mask element value must be equal GC_BGD or GC_FGD or GC_PR_BGD or GC_PR_FGD in function 'checkMask'
at org.bytedeco.opencv.global.opencv_imgproc.grabCut(Native Method)
at com. GrabCut.main(Ex5GrabCut.java:46)
I have also attached both the image and mask I got from Mask RCNN
With Regards,
Lariena