多线程2 winforms in 1(完全3个网络摄像头) [英] Multithreading 2 winforms in 1 ( 3 webcam in totally)

查看:77
本文介绍了多线程2 winforms in 1(完全3个网络摄像头)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好:



我有下一个问题。我有2个winform,第一个winform控制一个带摄像头的电机,两个电机都同步,每秒钟拍摄几张具有特定帧数的图像。这个项目非常特别和精致,因为我需要在帧之间具有相同时间的一系列图像



第二个winform是双摄像头跟踪。这比第一次更简单。



当我单独执行两个winforms时,第一个没有问题,这意味着帧之间的时间,或多或少,是const。



但是当我尝试制作一个基于用户控制的唯一winform时,加入两个winforms,当我激活双摄像头跟踪时,我可以看到帧之间的时间可能会比应该的时间少10毫秒。



我该怎么办?



对于双摄像头跟踪,我使用2个不同的AutoResetEvent来拍摄帧,其他线程用来组合两个摄像头。



对于同步电机和主摄像头我只使用一个线程具有高优先级。

Hello:

I have the next problem. I have 2 winform, the first winform control a motor with a camera where both are syncronized to take several images with a concrete number of frames per seconds. This project is very special and delicate because I need a sequence of images with the same time between frames

The second winform is a dual camera tracking. This is more simple than first.

When I execute both winforms separately there is no problem with the first, it means, that the time between frames, more or less, is const.

But when I try to make an only winform, based in usercontrols, join both winforms, when I active the dual camera tracking, I can see that the time between frames may vary 10milliseconds more o less that it should be.

What can I do?

For dual camera tracking I used 2 different AutoResetEvent to take the frames, and other thread to combine both cameras.

For syncronize motor and main camera I only use a thread with high priority.

推荐答案

10毫秒是相当不错的,在Windows方面 - 它不是一个实时操作系统,并且不能保证即使在同一个线程一个指令将在下一个之前执行:它取决于系统m load,可以是任何时间间隔。 Windows是一种先发制人的多任务系统,可以随时挂起一个线程,让优先级相同或更高的线程有机会。坦率地说,真的没有多少 - 如果有的话 - 你可以做些什么。



如果你必须,绝对必须,在窗口有准确的时间然后你正在寻找一个痛苦的世界,即使在.NET中尝试它,但你可能 - 我没有尝试过 - 使用P / Invoke而不是标准的多媒体定时器:http://msdn.microsoft.com/en-us/library/dd743609(v=VS.85).aspx [ ^ ]。



但是......如果你想要几乎同步的帧抓取,我认为你将不得不转向更低级别的软件。
10 milliseconds is pretty good, in Windows terms - it isn't a real-time operating system, and there is no guarantee that even on the same thread one instruction will be executed immediately before the next: it depends on the system load and can be any time interval at all. Windows is a pre-emptive multitasking system, and a thread can be suspended at any time to let an equal-or-higher priority thread have a chance. And to be frank, there really isn't much - if anything - you can do about it.

If you must, absolutely must, have accurate timing in windows then you are looking at a world of pain even trying it in .NET, but you might - and I haven't tried this - using multimedia timers via P/Invoke instead of standard ones: http://msdn.microsoft.com/en-us/library/dd743609(v=VS.85).aspx[^].

But ... I think you are going to have to move to a lower level of software if you want near-simultaneous frame grabs.


除了OriginalGriff的响应之外,这个准确无误,我不认为你会使用几个USB网络摄像头来做到这一点。由于您无法在同一USB控制器上同时从两个设备同时获取数据(请参阅USB代表的内容:通用串行总线),因此,如果不使用目的,获得所需的精确度是不可能的 - 专用硬件,例如同时支持多个源的视频捕获卡。
On top of OriginalGriff's response, which is dead on accurate, I don't think you're going to get away with using a couple of USB webcams to do this. Since you can't get data simultaneously from two devices on the same USB controller at the exact same time (refer to what USB stands for: Universal SERIAL Bus), getting the kind of accuracy you want is, frankly, impossible without using purpose-dedicated hardware, such as a video capture card that supports multiple sources at the same time.


这是一个额外的。我试图编程到同一个winform,只有一个表单,实际上正在工作,但当我尝试加入我的实际项目,我使用Usercontrols时,不工作。



也许有些东西是我看不到的,我不确切知道我的问题在哪里。



我会尝试编程一直到我成功。
That is extrange. I have tried to program into the same winform, only with a one form, and actually is working, but when I try to join with my actual project, where I use Usercontrols, don't work.

Maybe there is something that I can't see, I don't know exactly where is my problem.

I will try to program the same until I succeed.


这篇关于多线程2 winforms in 1(完全3个网络摄像头)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆