怎么调整Hololens2的视频和图片的分辨率(C++/CX)

花了三四天才搞定,记录下,供有需要的人参考

       //
        // Initialize media capture with the source group.
        //
        _mediaCapture = ref new Windows::Media::Capture::MediaCapture();
        
        auto settings =  ref new Windows::Media::Capture::MediaCaptureInitializationSettings();

        //
        // Select the source we will be reading from.
        //
        settings->SourceGroup =  group;         =======> 怎么找media group需要自己去研究了

        //
        // This media capture can share streaming with other apps.
        //

        // For HL1
        if (_deviceType == DeviceType::HL1)
        {
            settings->SharingMode =
                Windows::Media::Capture::MediaCaptureSharingMode::SharedReadOnly;
        }
        // For HL2
        if (_deviceType == DeviceType::HL2)
        {
            settings->SharingMode =
                Windows::Media::Capture::MediaCaptureSharingMode::ExclusiveControl;
        }

        //
        // Only stream video and don't initialize audio capture devices.
        //
        settings->StreamingCaptureMode =
            Windows::Media::Capture::StreamingCaptureMode::Video;

        //
        // Set to CPU to ensure frames always contain CPU SoftwareBitmap images,
        // instead of preferring GPU D3DSurface images.
        //
        settings->MemoryPreference =
            Windows::Media::Capture::MediaCaptureMemoryPreference::Cpu;

        //
        // Only stream video and don't initialize audio capture devices.
        //
        settings->StreamingCaptureMode =  Windows::Media::Capture::StreamingCaptureMode::Video;

        // HL2默认分辨率896 * 504,这里改成1280 * 760 提高二维码识别率
        // https://learn.microsoft.com/en-us/windows/mixed-reality/develop/advanced-concepts/locatable-camera-overview    ==》 官网对profile的说明
         dbg::trace(L"MediaFrameSourceGroup::TryInitializeMediaCaptureAsync: MediaCaptureVideoProfileMediaDescription  begin.");
         Windows::Foundation::Collections::IVectorView<Windows::Media::Capture::MediaCaptureVideoProfile^>^ profileList = _mediaCapture->FindAllVideoProfiles(group->Id); 
         for (Windows::Media::Capture::MediaCaptureVideoProfile^ profile : profileList)
         {
             bool found = false;
             for (Windows::Media::Capture::MediaCaptureVideoProfileMediaDescription^ desc : profile->SupportedPhotoMediaDescription)
             {
                 if ((desc->Height == 720) && (desc->Width == 1280) && (desc->FrameRate == 15))
                 {
                     settings->VideoProfile = profile;
                     settings->RecordMediaDescription = desc;
                     found = true;
                     dbg::trace(L"!!!!MediaCaptureVideoProfileMediaDescription found .");
                     break;
                 }
             }

             if (found == true)
                 break;
         }
        
        //
        // Initialize MediaCapture with the specified group.
        // This must occur on the UI thread because some device families
        // (such as Xbox) will prompt the user to grant consent for the
        // app to access cameras.
        // This can raise an exception if the source no longer exists,
        // or if the source could not be initialized.
        //
        return Concurrency::create_task(
            _mediaCapture->InitializeAsync(settings))               ====》设置生效
            .then([this](Concurrency::task<void> initializeMediaCaptureTask)
        {

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值