问题
I'm trying to do background subtraction with MOG2 in OpenCV 3.0 on my android phone. However, it seems that there are no suitable constructor to create a new BackgroundSubtractorMOG2 in version 3.0. My code lies down here.
@Override
public void onCameraViewStarted(int width, int height) {
mFrame = new Mat(height, width, CvType.CV_8UC4);
mFgMaskMOG = new Mat(height, width, CvType.CV_8UC1);
pMOG2 = new BackgroundSubtractorMOG2();
}
With these codes Android studio reminds me that the constructor has protected access. Besides, when I read java src code of BackgroundSubtractorMOG2 I find that there's one parameter for the constructor: long addr. The src code as following:
protected BackgroundSubtractorMOG2(long addr) { super(addr); }
I'm new to OpenCV4Android thus don't know how to construct such a class in java code. Any solution besides using older version of OpenCV4Android?
回答1:
You can use this code in OpenCV 3.0.0:
BackgroundSubtractorMOG2 pMOG2 = Video.createBackgroundSubtractorMOG2();
来源:https://stackoverflow.com/questions/30288953/creating-backgroundsubtractormog2-in-android-by-opencv-3-0-rc1