显示来自 IP 摄像机的已处理图像
我有一个提供图像的网络摄像机。然后通过 EmguCV 处理这些图像,然后我想显示处理后的图像。
为了显示图像,我使用以下代码:
Window1(){
...
this.Dispatcher.Hooks.DispatcherInactive
+= new EventHandler(Hooks_DispatcherInactive);
}
Hooks_DispatcherInactive(...)
{
Next()
}
Next() 调用调用图像处理方法并(应该)显示图像:
MatchResult? result = survey.Step();
if (result.HasValue)
{
Bitmap bit = result.Value.image.Bitmap;
ImageSource src = ConvertBitmap(bit);
show.Source = src;
...
}
当我连接普通的 30fps 网络摄像头时,这工作正常。但是,IPCam 的图像需要一秒钟才能到达这里,当我通过浏览器访问它们时也是如此。因此,与此同时,WPF 不显示任何内容,甚至不显示之前处理的图像。
如何让 WPF 至少显示上一张图像?
I have an IP-camera that serves images. These images are then processed via EmguCV and then I want to display the processed images.
To show the images, I use this code:
Window1(){
...
this.Dispatcher.Hooks.DispatcherInactive
+= new EventHandler(Hooks_DispatcherInactive);
}
Hooks_DispatcherInactive(...)
{
Next()
}
Next() the calls calls the image processing methods and (should) display the image:
MatchResult? result = survey.Step();
if (result.HasValue)
{
Bitmap bit = result.Value.image.Bitmap;
ImageSource src = ConvertBitmap(bit);
show.Source = src;
...
}
This works fine when I hook up a normal 30fps webcam. But, the IPCam's images take over a second to get here, also when I access them via a browser. So, in the mean time, WPF shows nothing, not even the previous image that was processed.
How can I get WPF to at least show the previous image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 创建(从数组) 或 创建(来自 IntPtr) 并在 WPF 的 Image 控件中显示该 BitmapSource,
或者您可以使用 DirectX 更快地完成此操作(对于 30fps(和 1fps)BitmapSource方法应该做)。
另外,请考虑不在视图中使用事件,而是使用绑定和命令。
You can copy the image's buffer into a new BitmapSource image of the same format (PixelFormat, Height, Width, stride) using Create (from Array) or Create (from IntPtr) and display that BitmapSource in WPF's Image control,
or you can use DirectX to do that faster (for 30fps (and 1fps) the BitmapSource approach should do).
Also, consider NOT using events in the view, instead use bindings and commands.