Android: Why can't I initialize BackgroundSubtractor with Video.createBackgroundSubtractorMOG2()?
I implemented my class with CameraBridgeViewBase.CvCameraViewListener2
. And here is my onCameraFrame() method that does the processing after frame grabbing before rendering the frame on screen:
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Mat frame=(Mat)inputFrame;
Mat fgMask=new Mat();
BackgroundSubtractor bs=Video.createBackgroundSubtractorMOG2();
bs.apply(frame,fgMask);
//return 4 channel as rgba or 1 channel as gray scale
return inputFrame.rgba();
}
I learn the syntax from here.
The problem is that Android Studio says 'Cannot resolve method createBackgroundSubtractorMOG2()' after I imported the Video class.
code runs fine on desktop java, so the problem unfortunately is between you and your ide (and there's not much we can do from here) ;(
apart from that,you have another problem: it does not make any sense, to create a new bgsubtractor per frame (onCameraFrame is the wrong place to create one).