Creating BackgroundSubtractorMOG2 in Android by OpenCV 3.0 RC1

99封情书 提交于 2020-01-24 18:49:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!