You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何关闭HoloLens 2 RGB相机自动曝光并设置指定曝光时长?

HoloLens 2 StreamRecorder 固定曝光时长问题修复

问题根源

调用SetValueAsync后自动曝光重新启用,是因为相机流未稳定时修改参数会触发自动控制逻辑重置;且原示例中InitializeAsync阶段相机流尚未启动,参数设置会被后续的自动初始化逻辑覆盖。

修复方案

1. 延迟到相机流启动后设置参数

不要在InitializeAsync中直接修改曝光参数,而是在第一个帧捕获完成后执行设置逻辑,确保相机流稳定:

// 在VideoFrameProcessor类中添加标记位
bool m_exposureConfigured = false;

void VideoFrameProcessor::ProcessFrame(winrt::Windows::Media::Capture::Frames::MediaFrameReader const& sender, winrt::Windows::Media::Capture::Frames::MediaFrameArrivedEventArgs const& args)
{
    if (!m_exposureConfigured)
    {
        m_exposureConfigured = true;
        // 异步执行曝光配置,避免阻塞帧处理
        auto configTask = [this]() -> winrt::IAsyncAction
        {
            auto exposureCtrl = m_mediaCapture.VideoDeviceController().ExposureControl();
            if (exposureCtrl.Supported())
            {
                // 先关闭自动曝光
                co_await exposureCtrl.SetAutoAsync(false);
                // 短暂等待确保设置生效
                co_await winrt::Windows::Foundation::TaskDelay(winrt::Windows::Foundation::TimeSpan(100000));
                // 设置10ms曝光时长(TimeSpan单位为100纳秒,10ms=100000)
                co_await exposureCtrl.SetValueAsync(winrt::Windows::Foundation::TimeSpan(100000));
                // 再次确认自动曝光关闭,防止被重置
                co_await exposureCtrl.SetAutoAsync(false);

                // 验证参数(可选,写入调试日志)
                auto currentAuto = exposureCtrl.Auto();
                auto currentExposure = exposureCtrl.Value().count();
                OutputDebugStringW((L"Auto Exposure Enabled: " + std::to_wstring(currentAuto) + L"\n").c_str());
                OutputDebugStringW((L"Current Exposure Time: " + std::to_wstring(currentExposure) + L"\n").c_str());
            }
        }();
    }

    // 原有帧处理逻辑...
}

2. 确认相机格式支持手动曝光

确保当前使用的RGB相机格式支持手动曝光控制,建议使用示例默认的1920x1080 YUY2格式,低分辨率或压缩格式可能不支持手动参数调整。

3. 避免参数设置顺序冲突

必须先关闭自动曝光,再设置固定值,且设置后再次确认自动曝光关闭,防止相机内部逻辑重置自动控制。

内容的提问来源于stack exchange,提问作者gemse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 22:35:07