I am going to do a backgroundsubtractor in a ROI area on my phone's camera, here is part of the code:
public static final int x = 10;
public static final int y = 400;
public static final int width = 1260;
public static final int height = 550;
……
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Mat frame = inputFrame.rgba();
Mat fgMask = new Mat();
Mat framecopy = frame.clone();
Imgproc.cvtColor(framecopy, framecopy, Imgproc.COLOR_RGBA2GRAY);
Mat ROI = framecopy.submat(y, y+height, x, x+width);
backSub.apply(ROI, fgMask, -1);
Imgproc.threshold(fgMask, fgMask, 127, 255, Imgproc.THRESH_BINARY);
Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT,new Size( 3, 3));
Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_CLOSE, kernel);
Imgproc.morphologyEx(fgMask, fgMask, Imgproc.MORPH_OPEN, kernel);
return framecopy;}
Then i run it on my mobilephone, the result is that the whole screen shows the gray scale , not having a backgroundsub effect in the ROI. I heard that submat references from mat (here is framecopy), so i think the ROI region of the framecopy should have backgroundsub effect.
I am a beginner, who can tell me why ? Many thanks !