Click here to Skip to main content
15,890,527 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am looking for a way to regularly capture quickly changing frames using general webcam.

For example, my pesudo code is
C++
int fps = 0, oldT = 0, curT = 0;
while (1)
{
   fps++;

   std::cout << fps << " ";

   oldT = curT;
   while (curT - oldT < 50) // 50ms time delay
   {   curT = timeGetTime(); }

    //capturing code

}

It means that webcam regularly captures the screen which shows increasing numbers. The desired results are the regularly captured images which contain the increasing numbers.

Some of the result images contained the same numbers and the result image sequence skipped some numbers such as

img1 -> 1
img2 -> 1 2
img3 -> 1 2 // unwanted result -> same number
img4 -> 1 2 // unwanted result -> same number
img5 -> 1 2 3 4 // unwanted result -> skip number
img6 -> 1 2 3 4 5
....

With poor background, I have tried to regularly capture frames. However, now, I doubt whether it is possible using webcam.

What I have tried:

I have used either videocapture in openCV or ISampleGrabber in directshow, however, I cannot obtain the desired results.

in my opinion, if these unwanted results are due to camera internal buffers for encoding, the unwanted result are regularly presented. But....I think that the unwanted results are irregular.

please, help me..
Posted
Updated 25-Apr-17 4:36am
v2

Some web cams havent such powerful hardware so there are limitations in the result. Try more powerful hardware or enhance the capture interval.

You can check the results by comparing the images and sort out unneeded files. The simplest solution could be by comparing the file size (and or the names?).

At last you make a picture comparision like with the OpenCV libraries like described in this tutorial.
 
Share this answer
 
Comments
begin0afresh 25-Apr-17 21:15pm    
As you mentioned, if i need images for different numbers, a picture comparision can be suceessful. However, I don't need images for different numbers, More specific, I want regular capture process. I will try the powerful hardware. Thanks for your answer.
If you're talking about looking at a number in a video frame on consecutive frames, yes, you're going to get missed and duplicate numbers on adjacent frames.

Windows is NOT a real-time operating system so timers don't "tick" on exact intervals. Also, there is no way to synchronize your timer "frame rate" with the frame rate of the video you're capturing with the web cam.

You WILL get numbers in your video that are missing and numbers that are duplicated. What you haven't seen yet in your limited testing is that you're going to get "tearing", a number that changes during the scan of the webcam sensor.

I'm assuming your doing some kind of OCR on the images as well to get these numbers. You cannot rely on any timer or any other time-based technique to fix the above problems. Your code is simply going to have to be able to detect and handle these cases according to your business rules, whatever those turn out to be. What do you do in the case of a duplicate number? What do you do in the case of a skipped number? What do you do in the case where the number wasn't recognized as a number? How do you detect these eventualities?
 
Share this answer
 
Comments
begin0afresh 25-Apr-17 21:19pm    
If I didn't mention that above, I already seen tearing numbers. Do you mean that it is impossible to synchronize timer "frame rate" with the frame rates of video? Thanks for the answer.
Dave Kreskowiak 25-Apr-17 21:26pm    
Like I already said, YES.

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