问题描述
我正在尝试使用opencv将视频设置为全屏显示.输入来自相机.它显示在中间的屏幕上,但不是全屏显示.相关代码:
i am trying to set a video to fullscreen using 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);
}
我尝试使用:
//mOpenCvCameraView.setScaleX(0.8f);
// mOpenCvCameraView.setScaleY(0.4f);
//mOpenCvCameraView.setMinimumHeight(800);
// mOpenCvCameraView.setMinimumWidth(1000);
但是它不起作用.
我如何伸展框架以填满整个屏幕?
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);
代码源于人脸检测OpenCV 2.4.2版.
The source of the code is from Face Detection OpenCV version 2.4.2.
这篇关于将opencv视频设置为全屏android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!