如何使用 OpenCV 在 Android 中设置相机分辨率? [英] How to set camera resolution in Android with OpenCV?

查看:23
本文介绍了如何使用 OpenCV 在 Android 中设置相机分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开发一款适用于 Android 的应用,我需要从相机中获取分辨率尽可能高的未压缩图片.我尝试了 takePicture 的 rawCallback 和 postviewCallback,但它们都不起作用.

I'm trying to develop an app for Android, and I would need to get uncompressed pictures with a resolution as high as possible from the camera. I tried takePicture's rawCallback and postviewCallback, but they are not working.

现在我正在尝试使用 VideoCapture 使用 OpenCV(2.4 版),但我被困在默认的 960x720 中,这对于我的需要来说很差;而我的手机,三星 Galaxy S3,理论上能够提供高达 8Mpx(图片为 3,264×2,448,视频为 1,920×1,080,根据维基百科).VideoCapture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH/HEIGHT, some number) 使相机返回我发现的黑色图像.

Right now I'm trying with OpenCV (version 2.4) using VideoCapture, but I'm stuck in the default 960x720, which is poor for what I need; and my phone, a Samsung Galaxy S3, is able to provide, theoretically, up to 8Mpx (3,264×2,448 for pictures, and 1,920×1,080 for video, according to Wikipedia). VideoCapture.set(Highgui.CV_CAP_PROP_FRAME_WIDTH/HEIGHT, some number) makes the camera return a black image as far as I've found.

有没有什么方法可以在不压缩的情况下通过 OpenCV 或 Android API 获得更高的分辨率?

Is there any way to obtain a higher resolution, either through OpenCV or with the Android API, without compressing?

如果以前有人问过这个问题,我真的很抱歉;我找了好几天,一无所获.

I'm really sorry if this has been asked before; I have been looking for days and I have found nothing.

感谢您的宝贵时间!

虽然这不是我要问的,但我发现有一种方法可以做一些非常相似的事情:如果您为相机设置 OnPreviewCallback,使用 setPreviewCallback,您确实会从相机获取原始图片数据(至少在我正在使用的 S3 中).我把它留在这里,以防将来有人发现它有用.

Although it is not exactly what I was asking, I found that there is a way to do something very similar: if you set an OnPreviewCallback for the Camera, using setPreviewCallback, you do get the raw picture data from the camera (at least in the S3 I'm working with). I leave it here in case somebody finds it useful in the future.

在下面的答案中解释了部分解决方案.总结一下,

A partial solution is explained in an answer below. To sum up,

vc.set(Highgui.CV_CAP_PROP_FRAME_WIDTH, desiredFrameWidth);
vc.set(Highgui.CV_CAP_PROP_FRAME_HEIGHT, desiredFrameHeight);

在某些条件下工作;详情请见下文.

works under some conditions; please see below for further detail.

推荐答案

您必须通过调用getSupportedPreviewSizes.

You have to get supported camera preview resoultions by calling getSupportedPreviewSizes.

在此之后,您可以使用方法 setPreviewSize.并且不要忘记 <代码>setParameters 最后.实际上,许多 OpenCV Android 示例都包含此信息(查看 sample3).

After this you can set any resolution with method setPreviewSize. And don't forget to setParameters in the end. Actally many OpenCV Android examples contain this information (look at sample3).

这篇关于如何使用 OpenCV 在 Android 中设置相机分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆