Opencv fullscreen using CameraBridgeViewBase android

坚强是说给别人听的谎言 提交于 2021-02-19 07:41:22

问题


i am trying to set up Opencv on android using the given tutorials as the base. i havenot been able to control the video size on the screen, i want to enlarge it to full screen. i am using the CameraBridgeViewBase object as the VideoCapture object does not work. does anyone know how to set up the picture to be full screen?

relevant code:

public class Sample3Native extends Activity implements CvCameraViewListener {
private static final String TAG = "OCVSample::Activity";

private Mat                    mRgba;
private Mat                    mGrayMat;
private Mat                    mFinalMat;


public CameraBridgeViewBase   mOpenCvCameraView;



private BaseLoaderCallback     mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {



        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");


                mOpenCvCameraView.enableView();

            } break;
            default:
            {
                super.onManagerConnected(status);
            } break;
        }
    }
};

public Sample3Native() {
    Log.i(TAG, "Instantiated new " + this.getClass());
}

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


    setContentView(R.layout.tutorial3_surface_view);


    mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial4_activity_surface_view);
    mOpenCvCameraView.setCvCameraViewListener(this);


}

any help would be much appreciated


回答1:


I got it working by following these steps.

  1. Remove ActionBar - Go to values/styles and change

    style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"

    to

    style name="AppTheme" parent="Theme.AppCompat.NoActionBar"

  2. Set max frame size - use this code to set the frame size.

    mOpenCvCameraView.setMaxFrameSize(720, 480);




回答2:


For anyone still looking for this, I have solved the issue (sort-of). I cannot seem to get this to work for OpenCV v 2.4.3. I have tried everything on the internet. However, in OpenCV 2.4.3.2 they have added a way to set the camera size

disconnectCamera();
mMaxHeight = //your desired height
mMaxWidth = //your desired width
connectCamera(mMaxWidth, mMaxHeight);

Check out the OpenCV Tutorial 5, specifically the SampleJavaCameraView -> setResolution Method




回答3:


You need to set your activity Theme as Full Screen in Android Manifest file. In your activity add android:theme="@android:style/Theme.NoTitleBar.Fullscreen".



来源:https://stackoverflow.com/questions/13438897/opencv-fullscreen-using-camerabridgeviewbase-android

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