简体   繁体   English

将opencv视频设置为全屏android

[英]setting opencv video to fullscreen android

i am trying to set a video to fullscreen using opencv.我正在尝试使用 opencv 将视频设置为全屏。 the input is coming from the camera.输入来自相机。 it shows on the screen in the center but not as 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;

private 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");

                // Load native library after(!) OpenCV initialization
                System.loadLibrary("native_sample");




                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);


}

i have tried using:我试过使用:

//mOpenCvCameraView.setScaleX(0.8f);
                   // mOpenCvCameraView.setScaleY(0.4f);

                //mOpenCvCameraView.setMinimumHeight(800);
               // mOpenCvCameraView.setMinimumWidth(1000);

but it doesnot work.但它不起作用。

how can i strech the frames to fill all of the screen?我怎样才能拉伸框架以填满整个屏幕?

You can get a list of the available resolutions or setup manually.您可以获得可用分辨率的列表或手动设置。

If you want to get the list of the available sizes and get the optimal camera size.如果您想获得可用尺寸的列表并获得最佳相机尺寸。

   if (mOpenCvCameraView != null) {
        List<Size> sizes = mOpenCvCameraView.getSupportedPreviewSizes();
        int mFrameWidth = width;
        int mFrameHeight = height;

        // selecting optimal camera size
        {

            double minDiff = Double.MAX_VALUE;
            for (Size size : sizes) {
                if (Math.abs(size.height - height) < minDiff) {
                    mFrameWidth = (int) size.width;
                    mFrameHeight = (int) size.height;
                    minDiff = Math.abs(size.height - height);
                }
            }
        }

        mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, mFrameWidth);
        mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, mFrameHeight);
    }

If the optimal camera size is not fullscreen, it is easy to get the great size that the camera support from the list.如果最佳相机尺寸不是全屏,很容易从列表中获得相机支持的大尺寸。

Other option is to set manually the size:其他选项是手动设置大小:

        mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 1000);
        mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, 800);

The source of the code is from Face Detection OpenCV version 2.4.2.代码来源来自人脸检测 OpenCV 2.4.2 版。

For those who google here and just want to change the resolution,对于那些在这里谷歌并且只想改变分辨率的人,

mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 1000) method is not working. mOpenCvCameraView.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, 1000)方法不起作用。

Try to use mOpenCvCameraView.setMaxFrameSize(640, 480);尝试使用mOpenCvCameraView.setMaxFrameSize(640, 480);

It works for OCV4Android2.4.5, tutorial 2, mixed processing.适用于OCV4Android2.4.5,教程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.我似乎无法让它适用于 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但是,在 OpenCV 2.4.3.2 中,他们添加了一种设置相机大小的方法

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

Check out the OpenCV Tutorial 5, specifically the SampleJavaCameraView -> setResolution Method查看 OpenCV 教程 5,特别是 SampleJavaCameraView -> setResolution Method

Not the best solution, but you can go to the AndroidManifest.xml and set android:screenOrientation="landscape"不是最好的解决方案,但您可以转到AndroidManifest.xml并设置android:screenOrientation="landscape"

With this you won't need to rotate de camera 90º, but your application will always be in landscape mode.有了这个,您不需要将相机旋转 90º,但您的应用程序将始终处于横向模式。

Natural camera orientation of the OpenCV camera is landscape so make your activity is like OpenCV 相机的自然相机方向是风景,所以让你的活动就像

android:screenOrientation="landscape"

and apply this theme in the Activity并在活动中应用此主题

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        ...
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
</style> 

this trick gives you a fullscreen camera.这个技巧给你一个全屏相机。

Try this replace试试这个替换

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

code in the onCreate with onCreate 中的代码

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM