Tag not monitored by Microsoft.
FaceDetector::CreateAsync DetectFacesAsync 创建异步任务各种异常
Hyy
0
Reputation points
create_task创建FaceDetector::CreateAsync()及DetectFacesAsync异步任务会报各种异常,参数错误,或者访问位置异常等,我的写法有什么问题,我该怎么等待并获取结果,c++20的co_wait可以实现,但是我的是uwpc++项目,需要zw编译,vs2022显示c++20和zw冲突
void FrameRenderer::DetectFace(SoftwareBitmap^ input) {
static const BitmapPixelFormat InputPixelFormat = BitmapPixelFormat::Gray8;
if (FaceDetector::IsBitmapPixelFormatSupported(InputPixelFormat) && !detectedFace)
{
if (input->PixelHeight > 0 && input->PixelWidth > 0)
{
try
{
std::shared_ptr<SoftwareBitmap^> detectorInput = std::make_shared<SoftwareBitmap^>(SoftwareBitmap::Convert(input, InputPixelFormat));
if (detectorInput != nullptr && (*detectorInput)->PixelHeight > 0 && (*detectorInput)->PixelWidth > 0)
{
static IAsyncOperation<FaceDetector^>^ createOp = FaceDetector::CreateAsync();
create_task(createOp)
.then([detectorInput, this](FaceDetector^ faceDetector)
{
OutputDebugString(L"detectorInput != nullptr");
static IAsyncOperation<IVector<DetectedFace^>^>^ op = faceDetector->DetectFacesAsync((*detectorInput));
return op;
}, task_continuation_context::use_current())
.then([this](IVector<DetectedFace^>^ faces)
{
if (faces != nullptr && faces->Size != 0)
{
//detectedFace = true;
}
}, task_continuation_context::use_current())
.then([](task<void> previousTask) {
try {
previousTask.get();
}
catch (Platform::InvalidArgumentException^ e)
{
OutputDebugString(e->Message->Data());
}
catch (Platform::Exception^ e)
{
OutputDebugString(e->Message->Data());
}
});
}
}
catch (Platform::InvalidArgumentException^ e)
{
OutputDebugString(e->Message->Data());
}
catch (Platform::Exception^ e)
{
OutputDebugString(e->Message->Data());
}
}
}
}
Community Center | Not monitored
Community Center | Not monitored
Sign in to answer