无法让 FaceTracker class 在 HoloLens 2 上工作
Can't get FaceTracker class to work on HoloLens 2
我无法让 FaceTracker Class 在 HoloLens 2 上工作。
一旦我尝试用 ProcessNextFrameAsync Method
检测面孔,我就会得到以下类型的异常:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error
这只是错误消息的第一部分,如果需要更多信息,我可以添加。
请参阅此处的最小示例。
public async void Start()
{
var selectedGroup = await FindCameraAsync();
await StartMediaCaptureAsync(selectedGroup);
}
private async Task StartMediaCaptureAsync(MediaFrameSourceGroup sourceGroup)
{
faceTracker = await FaceTracker.CreateAsync();
this.mediaCapture = new MediaCapture();
await this.mediaCapture.InitializeAsync(settings);
this.frameProcessingTimer = ThreadPoolTimer.CreatePeriodicTimer(ProcessCurrentVideoFrameAsync, timerInterval);
}
private async Task ProcessCurrentVideoFrameAsync()
{
const BitmapPixelFormat InputPixelFormat = BitmapPixelFormat.Nv12;
var deviceController = this.mediaCapture.VideoDeviceController;
this.videoProperties = deviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
VideoFrame videoFrame = new VideoFrame(InputPixelFormat, (int)this.videoProperties.Width (int)this.videoProperties.Height);
IList<DetectedFace> detectedFaces;
try
{
detectedFaces = await faceTracker.ProcessNextFrameAsync(videoFrame);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine($"Failed with Exception: {e.ToString()}");
return;
}
videoFrame.Dispose();
}
- 我得到了
MediaFrameSourceKind.Color
和 MediaStreamType.VideoPreview
FindCameraAsync()
合适的相机。我认为哪个效果很好。
- 开始
MediaCapture
和FaceTracker
内StartMediaCaptureAsync()
- 尝试检测
ProcessCurrentVideoFrameAsync()
中的人脸
以下是我测试过的东西和收到的信息:
- 我有一张格式为
Nv12
、PixelWidth
1504 和 PixelHeigt
846 的图片
- Unity 中的权限已授予网络摄像头、图片库和麦克风
- 该应用程序是使用 Il2CPP 编译的
- 启动应用程序后出现
No capture devices are available.
消息。在其他文章中提到缺少权限(网络摄像头或麦克风),但事实并非如此。但仍然可以连接。
- 我参考了Track faces in a sequence of frames and Basic Face Tracking sample
非常感谢每一次的鼓励和思考。
2020 年 7 月 14 日更新
我刚刚在本地存储在 HoloLens 2 上的几张单独图像上尝试了 FaceDetector
。效果很好。
尽管 FaceDetector
和 FaceTracker
不完全相同,但它们非常相似。所以我猜这个问题在某种程度上与 MediaCapture
.
有关
接下来我将尝试使用 MediaCapture
捕获图像并使用 FaceDetector
进行处理。
如果在此期间有人有更多想法,我将不胜感激。
这是一个官方示例,展示了如何使用 FaceTracker class 在视频流中查找人脸:Basic face tracking sample。而在第 256 行,这是从捕获设备获取预览帧的要点。
但是,根据您的代码,您创建了一个 VideoFrame
object and specified the properties and format to it, but you are missing invoke GetPreviewFrameAsync
来将本机网络摄像头框架转换为 VideoFrame
对象。
您可以尝试使用以下代码修复:
private async Task ProcessCurrentVideoFrameAsync()
{
const BitmapPixelFormat InputPixelFormat = BitmapPixelFormat.Nv12;
var deviceController = this.mediaCapture.VideoDeviceController;
this.videoProperties = deviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
VideoFrame videoFrame = new VideoFrame(InputPixelFormat, (int)this.videoProperties.Width (int)this.videoProperties.Height);
//add this line code.
await this.mediaCapture.GetPreviewFrameAsync(videoFrame);
我无法让 FaceTracker Class 在 HoloLens 2 上工作。
一旦我尝试用 ProcessNextFrameAsync Method
检测面孔,我就会得到以下类型的异常:
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error
这只是错误消息的第一部分,如果需要更多信息,我可以添加。
请参阅此处的最小示例。
public async void Start()
{
var selectedGroup = await FindCameraAsync();
await StartMediaCaptureAsync(selectedGroup);
}
private async Task StartMediaCaptureAsync(MediaFrameSourceGroup sourceGroup)
{
faceTracker = await FaceTracker.CreateAsync();
this.mediaCapture = new MediaCapture();
await this.mediaCapture.InitializeAsync(settings);
this.frameProcessingTimer = ThreadPoolTimer.CreatePeriodicTimer(ProcessCurrentVideoFrameAsync, timerInterval);
}
private async Task ProcessCurrentVideoFrameAsync()
{
const BitmapPixelFormat InputPixelFormat = BitmapPixelFormat.Nv12;
var deviceController = this.mediaCapture.VideoDeviceController;
this.videoProperties = deviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
VideoFrame videoFrame = new VideoFrame(InputPixelFormat, (int)this.videoProperties.Width (int)this.videoProperties.Height);
IList<DetectedFace> detectedFaces;
try
{
detectedFaces = await faceTracker.ProcessNextFrameAsync(videoFrame);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine($"Failed with Exception: {e.ToString()}");
return;
}
videoFrame.Dispose();
}
- 我得到了
MediaFrameSourceKind.Color
和MediaStreamType.VideoPreview
FindCameraAsync()
合适的相机。我认为哪个效果很好。 - 开始
MediaCapture
和FaceTracker
内StartMediaCaptureAsync()
- 尝试检测
ProcessCurrentVideoFrameAsync()
中的人脸
以下是我测试过的东西和收到的信息:
- 我有一张格式为
Nv12
、PixelWidth
1504 和PixelHeigt
846 的图片
- Unity 中的权限已授予网络摄像头、图片库和麦克风
- 该应用程序是使用 Il2CPP 编译的
- 启动应用程序后出现
No capture devices are available.
消息。在其他文章中提到缺少权限(网络摄像头或麦克风),但事实并非如此。但仍然可以连接。 - 我参考了Track faces in a sequence of frames and Basic Face Tracking sample
非常感谢每一次的鼓励和思考。
2020 年 7 月 14 日更新
我刚刚在本地存储在 HoloLens 2 上的几张单独图像上尝试了 FaceDetector
。效果很好。
尽管 FaceDetector
和 FaceTracker
不完全相同,但它们非常相似。所以我猜这个问题在某种程度上与 MediaCapture
.
接下来我将尝试使用 MediaCapture
捕获图像并使用 FaceDetector
进行处理。
如果在此期间有人有更多想法,我将不胜感激。
这是一个官方示例,展示了如何使用 FaceTracker class 在视频流中查找人脸:Basic face tracking sample。而在第 256 行,这是从捕获设备获取预览帧的要点。
但是,根据您的代码,您创建了一个 VideoFrame
object and specified the properties and format to it, but you are missing invoke GetPreviewFrameAsync
来将本机网络摄像头框架转换为 VideoFrame
对象。
您可以尝试使用以下代码修复:
private async Task ProcessCurrentVideoFrameAsync()
{
const BitmapPixelFormat InputPixelFormat = BitmapPixelFormat.Nv12;
var deviceController = this.mediaCapture.VideoDeviceController;
this.videoProperties = deviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
VideoFrame videoFrame = new VideoFrame(InputPixelFormat, (int)this.videoProperties.Width (int)this.videoProperties.Height);
//add this line code.
await this.mediaCapture.GetPreviewFrameAsync(videoFrame);