Vuforia设置摄像头自动聚焦和分辨率的问题
2017-10-21 10:26
417 查看
在使用Vuforia进行AR开发时,如果使用的是具有高分辨率和对焦功能的摄像头进行识别,需要我们注意进行相关参数的设置。
以unity5.6.0和6.2.6的Vuforia SDK为环境进行开发。
(1)设置连续自动对焦功能。
这一功能的设置在官网有说明,使用SDK时进行重载就可以了。原文链接地址在这里
在ARCamera直接加载FrameRateSettings.cs脚本,在这个脚本中进行设置:
void Start ()
{
VuforiaBehaviour.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
VuforiaBehaviour.Instance.RegisterOnPauseCallback(OnPaused);
}
private void OnVuforiaStarted ()
{
// Try register camera image format
if (CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.RGBA8888, true))
{
Debug.Log("Successfully registered pixel format " + Image.PIXEL_FORMAT.RGBA8888.ToString());
}
else
{
Debug.LogError(
"\nFailed to register pixel format: " + Image.PIXEL_FORMAT.RGBA8888.ToString() +
"\nThe format may be unsupported by your device." +
"\nConsider using a different pixel format.\n");
// mFormatRegistered = false;
}
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
// Query Vuforia for recommended frame rate and set it in Unity
int targetFps = VuforiaRenderer.Instance.GetRecommendedFps(VuforiaRenderer.FpsHint.NONE);
// By default, we use Application.targetFrameRate to set the recommended frame rate.
// Google Cardboard does not use vsync, and OVR explicitly disables it. If developers
// use vsync in their quality settings, they should also set their QualitySettings.vSyncCount
// according to the value returned above.
// e.g: If targetFPS > 50 --> vSyncCount = 1; else vSyncCount = 2;
if (Application.targetFrameRate != targetFps)
{
Debug.Log("Setting frame rate to " + targetFps + "fps");
Application.targetFrameRate = targetFps;
}
}
private void OnPaused(bool paused)
{
if (!paused) // resumed
{
// Set again autofocus mode when app is resumed
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
}
(2)设置摄像头分辨率
根据这篇文章中的介绍,有了思路。这一个Vuforia也留给了我们接口文件,直接按照格式对应的相机名称进行修改或添加对应的相机分辨率就可以了。
这个接口文件名称是profiles.xml,位置在Vuforia\Editor\WebcamProfiles中,打开会大吃一惊,各种常用的网络摄像头都有,但是默认的分辨率都是640*480,
这里提供WebcamProfiles文件的下载,请点击这里下载。
但是并不需要更改这个文件夹的位置,保持其目录不变,修改完毕即可。
同时读取Image参数可以发现分辨率已经更改了。
void Start (){
VuforiaBehaviour.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated);
}
void OnTrackablesUpdated()
{
if (true)
{
if (true)
{
Vuforia.Image image = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888);
if (image != null)
{
Debug.Log(
"\nImage Format: " + image.PixelFormat +
"\nImage Size: " + image.Width + "x" + image.Height +
"\nBuffer Size: " + image.BufferWidth + "x" + image.BufferHeight +
"\nImage Stride: " + image.Stride + "\n"+
"w:" + VuforiaRenderer.Instance.VideoBackgroundTexture.texelSize.x+"\n"+
"H:" + VuforiaRenderer.Instance.VideoBackgroundTexture.texelSize.y+"\n"
);
byte[] pixels = image.Pixels;
if (pixels != null && pixels.Length > 0)
{
Debug.Log(
"\nImage pixels: " +
pixels[0] + ", " +
pixels[1] + ", " +
pixels[2] + ", ...\n"
);
}
}
}
}
}
需要注意一定要用对应的摄像头名称,如果不确定摄像头名称用程序读出来。
using UnityEngine;
using System.Collections;
public class webCamFetch : MonoBehaviour {
WebCamTexture webcamtexture;
void Start()
{
WebCamDevice[] devices = WebCamTexture.devices;
if (devices.Length > 0) {
Debug.Log ("DevicesName" + devices [0].name);
}
}
}
好了,运行发现,摄像头分辨率变得更清晰了,可识别的距离也增大了。
以unity5.6.0和6.2.6的Vuforia SDK为环境进行开发。
(1)设置连续自动对焦功能。
这一功能的设置在官网有说明,使用SDK时进行重载就可以了。原文链接地址在这里
在ARCamera直接加载FrameRateSettings.cs脚本,在这个脚本中进行设置:
void Start ()
{
VuforiaBehaviour.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
VuforiaBehaviour.Instance.RegisterOnPauseCallback(OnPaused);
}
private void OnVuforiaStarted ()
{
// Try register camera image format
if (CameraDevice.Instance.SetFrameFormat(Image.PIXEL_FORMAT.RGBA8888, true))
{
Debug.Log("Successfully registered pixel format " + Image.PIXEL_FORMAT.RGBA8888.ToString());
}
else
{
Debug.LogError(
"\nFailed to register pixel format: " + Image.PIXEL_FORMAT.RGBA8888.ToString() +
"\nThe format may be unsupported by your device." +
"\nConsider using a different pixel format.\n");
// mFormatRegistered = false;
}
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
// Query Vuforia for recommended frame rate and set it in Unity
int targetFps = VuforiaRenderer.Instance.GetRecommendedFps(VuforiaRenderer.FpsHint.NONE);
// By default, we use Application.targetFrameRate to set the recommended frame rate.
// Google Cardboard does not use vsync, and OVR explicitly disables it. If developers
// use vsync in their quality settings, they should also set their QualitySettings.vSyncCount
// according to the value returned above.
// e.g: If targetFPS > 50 --> vSyncCount = 1; else vSyncCount = 2;
if (Application.targetFrameRate != targetFps)
{
Debug.Log("Setting frame rate to " + targetFps + "fps");
Application.targetFrameRate = targetFps;
}
}
private void OnPaused(bool paused)
{
if (!paused) // resumed
{
// Set again autofocus mode when app is resumed
CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
}
(2)设置摄像头分辨率
根据这篇文章中的介绍,有了思路。这一个Vuforia也留给了我们接口文件,直接按照格式对应的相机名称进行修改或添加对应的相机分辨率就可以了。
这个接口文件名称是profiles.xml,位置在Vuforia\Editor\WebcamProfiles中,打开会大吃一惊,各种常用的网络摄像头都有,但是默认的分辨率都是640*480,
这里提供WebcamProfiles文件的下载,请点击这里下载。
但是并不需要更改这个文件夹的位置,保持其目录不变,修改完毕即可。
同时读取Image参数可以发现分辨率已经更改了。
void Start (){
VuforiaBehaviour.Instance.RegisterTrackablesUpdatedCallback(OnTrackablesUpdated);
}
void OnTrackablesUpdated()
{
if (true)
{
if (true)
{
Vuforia.Image image = CameraDevice.Instance.GetCameraImage(Image.PIXEL_FORMAT.RGBA8888);
if (image != null)
{
Debug.Log(
"\nImage Format: " + image.PixelFormat +
"\nImage Size: " + image.Width + "x" + image.Height +
"\nBuffer Size: " + image.BufferWidth + "x" + image.BufferHeight +
"\nImage Stride: " + image.Stride + "\n"+
"w:" + VuforiaRenderer.Instance.VideoBackgroundTexture.texelSize.x+"\n"+
"H:" + VuforiaRenderer.Instance.VideoBackgroundTexture.texelSize.y+"\n"
);
byte[] pixels = image.Pixels;
if (pixels != null && pixels.Length > 0)
{
Debug.Log(
"\nImage pixels: " +
pixels[0] + ", " +
pixels[1] + ", " +
pixels[2] + ", ...\n"
);
}
}
}
}
}
需要注意一定要用对应的摄像头名称,如果不确定摄像头名称用程序读出来。
using UnityEngine;
using System.Collections;
public class webCamFetch : MonoBehaviour {
WebCamTexture webcamtexture;
void Start()
{
WebCamDevice[] devices = WebCamTexture.devices;
if (devices.Length > 0) {
Debug.Log ("DevicesName" + devices [0].name);
}
}
}
好了,运行发现,摄像头分辨率变得更清晰了,可识别的距离也增大了。
相关文章推荐
- Vuforia7.0新版本,自定义修改摄像头分辨率,解决辣鸡摄像头放大图像问题
- 关于unity中使用Vuforia制作AR场景如何设置自动对焦的问题(全网独家)
- 【计算机视觉】关于用opencv 设置摄像头读分辨率问题的若干说明
- OpenCV摄像头采集分辨率设置问题
- IAMStreamConfig 设置问题/设置分辨率/准确获取filter
- 【Android】设置摄像头方向、打开线程与预览线程、设置参数、Camera外设按键、自动对焦与触摸对焦、拍照、人脸检测、位置管理、旋转管理、变焦、录像
- 设置EditText光标不聚焦,,软件盘不自动弹出
- opencv 摄像头分辨率设置
- 自动横屏、滑盖(侧滑)手机的Camera相机设置问题(preView黑屏)
- [转]HttpWebRequest提高效率之连接数,代理,自动跳转,gzip请求等设置有关问题
- 深度揭秘android摄像头的autoFocus-----循环自动聚焦的实现(Android Camera AutoFocus on Demand)
- 关于vuforia前置摄像头模型反转等问题
- cocos2d-x3.0中图片分辨率自动适配设置以及源码,原理分析。
- mui:自动消失提示框位置问题设置
- opencv设置摄像头分辨率
- Unity3d vuforia 调用三星平板相机聚焦的问题
- 探究客户端浏览器分辨率的自适应问题(如何使网站脚本自动适应客户端分辨率)(3)
- 关于安卓手机硬编码分辨率设置问题
- EditText自动获取焦点问题设置
- TextView设置文字包含中英文时自动换行问题的终极解决方案