1 | initial version |
I did it in onCameraFrame():
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
mRgba = inputFrame.rgba();
Imgproc.cvtColor(mRgba, mRgb, Imgproc.COLOR_RGBA2RGB); //the apply function will throw the above error if you don't feed it an RGB image
sub.apply(mRgb, mFGMask, -1); //apply() exports a gray image by definition
Imgproc.cvtColor(mFGMask, mRgba, Imgproc.COLOR_GRAY2RGBA);
return mRgba;
}
The global vars needed:
private BackgroundSubtractorMOG2 sub = new BackgroundSubtractorMOG2(10, 25, false);
private Mat mRgb=new Mat();
private Mat mFGMask=new Mat();
private Mat mRgba=new Mat();
Credits to Austin from Stack Overflow.