gpt4 book ai didi

ios - DJI SDK 获取最后一张图片

转载 作者:行者123 更新时间:2023-11-30 11:24:01 25 4
gpt4 key购买 nike

我目前正在尝试使用移动 SDK 访问 DJI Phantom 4 拍摄的最后一张图像。我看过:How to programmatically download Images from drone using the IOS DJI-SDK然而,它有所帮助,在 .refreshFileList() 调用中,会抛出一个错误,提示“此进程的执行已超时(代码 -1003)”。

任何帮助将不胜感激!这是我的代码:

/***** Setup Camera *****/

// get current product
guard let drone = DJISDKManager.product() else {
print("Product is connected but DJISDKManager.product is nil when attempting to download media")
return
}

// Get camera on drone
guard let camera: DJICamera = drone.camera else {
print("Unable to detect Camera in initDownload()")
return
}

print("Successfully detected the camera")


// take picture when project starts
camera.startShootPhoto(completion: { (error) in

if (error != nil) {
print("Shoot photo error: \(error.debugDescription)")
}

})


/***** Get Last Picture *****/

// check if we can download images with the product
if !camera.isMediaDownloadModeSupported() {
print("Product does not support media download mode")
return
}

print("before set mode...")

// switch camera mode to allow for media downloads
camera.setMode( .mediaDownload, withCompletion: {(error) in

print("in set mode...")

if error != nil {

print(("\(error!.localizedDescription)"))

} else {

// get the media manager from the drone to gain access to the files
let manager = camera.mediaManager!

manager.refreshFileList(of: DJICameraStorageLocation.sdCard, withCompletion: { (error) in

print("in refresh file list...")

if error != nil {

///////TIMES OUT HERE/////////

print("Refresh error State: \(manager.sdCardFileListState.rawValue)")
print("Error refreshing list: \(error!.localizedDescription)")

}else {

print("Refreshed file list")
print("No error State: \(manager.sdCardFileListState.rawValue)")

// get list of files
guard let files = manager.sdCardFileListSnapshot() else {
print("No files to download")
return
}

print("There are files to download.. Beginning Download")
print(("files \(files.count)"))
}
}) // end of file-refresh block
} // end of if else
})// end of camera setMode block

最佳答案

您的代码的问题是您没有等待 startShootPhoto 操作完成后才更改模式。这可能是导致您的错误的原因。

这是您的函数的工作版本

 func shootPhoto() {
guard let drone = (DJISDKManager.product() as? DJIAircraft) else {
print("Product is connected but DJISDKManager.product is nil when attempting to download media")
return
}

// Get camera on drone
guard let camera: DJICamera = drone.camera else {
print("Unable to detect Camera in initDownload()")
return
}

print("Successfully detected the camera")


// take picture when project starts
camera.startShootPhoto(completion: { (error) in

if (error != nil) {
print("Shoot photo error: \(error.debugDescription)")
}
else {
self.getLastImage(camera: camera)
}

})

}

func getLastImage(camera: DJICamera) {
/***** Get Last Picture *****/

// check if we can download images with the product
if !camera.isMediaDownloadModeSupported() {
print("Product does not support media download mode")
return
}

print("before set mode...")
let retry = RetryManager() // Run the same block multiple times if the command has an error
// switch camera mode to allow for media downloads
retry.runBlock(withRetries: 5) {
camera.setMode( .mediaDownload, withCompletion: {(error) in

print("in set mode...")

if error != nil {

print(("\(error!.localizedDescription)"))

} else {
retry.stop()
// get the media manager from the drone to gain access to the files
let manager = camera.mediaManager!

manager.refreshFileList(of: DJICameraStorageLocation.sdCard, withCompletion: { (error) in

print("in refresh file list...")

if error != nil {

///////TIMES OUT HERE/////////

print("Refresh error State: \(manager.sdCardFileListState.rawValue)")
print("Error refreshing list: \(error!.localizedDescription)")

}else {

print("Refreshed file list")
print("No error State: \(manager.sdCardFileListState.rawValue)")

// get list of files
guard let files = manager.sdCardFileListSnapshot() else {
print("No files to download")
return
}

print("There are files to download.. Beginning Download")
print(("files \(files.count)"))
}
}) // end of file-refresh block
} // end of if else
retry.proceed()
})// end of camera setMode block
}

}

这段代码对我有用,这是重试管理器的要点,自从前几次尝试失败后我不得不使用它。 https://gist.github.com/justinmiller62/4c76d9704524fd8aaa60e166a5cccea8

此外,如果您希望代码内联而不是像这样嵌套,您可以使用信号量等待上一个函数完成。

关于ios - DJI SDK 获取最后一张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50957589/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com