它与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),问题解决了