c# - VideoFeed 无法在使用最新 Windows SDK 的 MavicAir 2 上运行
问题描述
它与 Windows SDK 0.2.0 配合良好,我能够控制无人机并获得 FPV。我意识到发布了一个新版本的 SDK,我尝试了一下。我发现最新的SDK只支持移动命令,即使使用DJI提供的示例代码,我也无法从无人机获取任何视频数据。谁能告诉我如何使用这个 sdk 获取视频反馈?
这是 git 示例代码:
public sealed partial class FPVPage : Page
{
private DJIVideoParser.Parser videoParser;
public FPVPage()
{
this.InitializeComponent();
}
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedFrom(e);
InitializeVideoFeedModule();
await DJI.WindowsSDK.DJISDKManager.Instance.ComponentManager.GetCameraHandler(0, 0).SetCameraWorkModeAsync(new CameraWorkModeMsg { value = CameraWorkMode.SHOOT_PHOTO });
}
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
UninitializeVideoFeedModule();
}
private async void InitializeVideoFeedModule()
{
//Must in UI thread
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
//Raw data and decoded data listener
if (videoParser == null)
{
videoParser = new DJIVideoParser.Parser();
videoParser.Initialize(delegate (byte[] data)
{
//Note: This function must be called because we need DJI Windows SDK to help us to parse frame data.
return DJISDKManager.Instance.VideoFeeder.ParseAssitantDecodingInfo(0, data);
});
//Set the swapChainPanel to display and set the decoded data callback.
videoParser.SetSurfaceAndVideoCallback(0, 0, swapChainPanel, ReceiveDecodedData);
DJISDKManager.Instance.VideoFeeder.GetPrimaryVideoFeed(0).VideoDataUpdated += OnVideoPush;
}
//get the camera type and observe the CameraTypeChanged event.
DJISDKManager.Instance.ComponentManager.GetCameraHandler(0, 0).CameraTypeChanged += OnCameraTypeChanged;
var type = await DJISDKManager.Instance.ComponentManager.GetCameraHandler(0, 0).GetCameraTypeAsync();
OnCameraTypeChanged(this, type.value);
});
}
private void UninitializeVideoFeedModule()
{
if (DJISDKManager.Instance.SDKRegistrationResultCode == SDKError.NO_ERROR)
{
videoParser.SetSurfaceAndVideoCallback(0, 0, null, null);
DJISDKManager.Instance.VideoFeeder.GetPrimaryVideoFeed(0).VideoDataUpdated -= OnVideoPush;
}
}
//raw data
void OnVideoPush(VideoFeed sender, byte[] bytes)
{
videoParser.PushVideoData(0, 0, bytes, bytes.Length);
}
//Decode data. Do nothing here. This function would return a bytes array with image data in RGBA format.
async void ReceiveDecodedData(byte[] data, int width, int height)
{
}
//We need to set the camera type of the aircraft to the DJIVideoParser. After setting camera type, DJIVideoParser would correct the distortion of the video automatically.
private void OnCameraTypeChanged(object sender, CameraTypeMsg? value)
{
if (value != null)
{
switch (value.Value.value)
{
case CameraType.MAVIC_2_ZOOM:
this.videoParser.SetCameraSensor(AircraftCameraType.Mavic2Zoom);
break;
case CameraType.MAVIC_2_PRO:
this.videoParser.SetCameraSensor(AircraftCameraType.Mavic2Pro);
break;
default:
this.videoParser.SetCameraSensor(AircraftCameraType.Others);
break;
}
}
}
}
解决方案
DJI技术团队快速上传新版本sdk(0.3.1),问题解决
推荐阅读
- html - 如何去除字体中的 3d 效果
- c# - 如何使用 ServiceStack 和 AAD 授权 React/TypeScript 应用程序
- mysql - 选择数据“不存在”并选择为空或“为空”的列 - MySQL
- javascript - 如何在 Cordova 中使用 Electron 平台执行 Bash 命令
- chai - 在柏树中,因为()函数在哪里?
- python - Model.fit_generator 抛出运行时错误:
- alexa - 如何在 Alexa 技能中创建复合插槽类型?
- django - Django CMS (3.6.0) 自动语言切换/检测未按预期工作
- sql - 使用带有实体框架的 .SqlQuery 处理来自存储过程的多个结果集
- c - 如何读入文件,然后将文件中的每个结构放入数组中?