Click here to Skip to main content
15,888,162 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
Posted
Comments
Sergey Alexandrovich Kryukov 5-May-14 11:42am    
The problem is not clear. One form or two, does not matter, still the UI thread is the same thread. The OS is not the real-time, but the video usually does not go out of sync, unless you have some extreme overloading of the system. Or you are synchronize them incorrectly, I don't know how. The fact that you are relying on high priority thread suggests that you are synchronizing thing is a totally wrong way. Priorities are only good for balancing average performance or throughput, not for synchronization. This is not synchronization, this is race condition.
—SA

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.
 
Share this answer
 
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.
 
Share this answer
 
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900