我正在开发一个通用 Windows 平台应用程序 (UWP),我在其中使用 C++ 作为主要语言。我想同时从两个相机读取。一个摄像头属于 Kinect RGB 摄像头,另一个摄像头属于 Kinect 深度摄像头。到目前为止,我已经设法使用这段代码读取了一个:
void SDKTemplate::Scenario4_ReproVideo::Grabar_Click(Platform::Object^
sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
CameraCaptureUI^ dialog = ref new CameraCaptureUI();
dialog->VideoSettings->Format = CameraCaptureUIVideoFormat::Mp4;
Windows::Foundation::Collections::IPropertySet^ appSettings = ApplicationData::Current->LocalSettings->Values;
concurrency::task<StorageFile^>(dialog->CaptureFileAsync(CameraCaptureUIMode::Video)).then([this](StorageFile^ file) {
if (file != nullptr) {
concurrency::task<Streams::IRandomAccessStream^> (file->OpenAsync(FileAccessMode::Read)).then([this] (Streams::IRandomAccessStream^ stream){
CapturedVideo->SetSource(stream, "video/mp4");
logger->Text = "recording";
});
Windows::Foundation::Collections::IPropertySet^ appSettings = ApplicationData::Current->LocalSettings->Values;
appSettings->Insert("CapturedVideo", PropertyValue::CreateString(file->Path));
}
else {
logger->Text = "Something went wrong or was cancelled";
}
});
}
通过这样做,我可以从其中一台摄像机可靠地进行录制。我的问题是我需要同时从两个摄像头进行录制,因为我需要深度和 RGB 来处理视频。
我是并发新手,有没有办法(越简单越好)同时实现两路录音?
最佳答案
在 UWP 应用中,我们可以使用 MediaCapture 捕获照片和视频提供从捕获设备捕获照片、音频和视频的功能的类。见题目Basic photo, video, and audio capture with MediaCapture .
我们可以初始化多个MediaCapture实例然后使用 MediaFrameReader 读取帧类(class)。看题目Discover and select camera capabilities with camera profiles和 Process media frames with MediaFrameReader并查看官方样本 CameraFrames .
另外,UWP多机位采集也有类似的帖子,大家也可以引用一下:
关于c++ - 如何同时使用两个CameraCaptureUI(UWP/C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50739627/