Question on frame rate
See original GitHub issueI was using the CalculateFPSExample.java app in order to test the frame rate. As expected with my HD cam it is always about 30 fps.
Then I combined it with the preview display and was surprised, that the frame rate is only about 15 fps now. The same happens, if I do a webcam.open(false)
w/o preview
Any idea, why? For me this is a bit too much “Heisenbergsche Unschärfe” (if you know what I mean) 😃
My sample app:
public static void main(String[] args) {
final Webcam webcam = Webcam.getDefault();
webcam.setViewSize(WebcamResolution.VGA.getSize());
webcam.open();
// Uncommenting this reduces the framerate by 50 %
// final WebcamPanel panel = new WebcamPanel(webcam);
// panel.setFPSDisplayed(true);
// panel.setImageSizeDisplayed(true);
// panel.setMirrored(true);
// JFrame window = new JFrame("Test webcam panel");
// window.setLayout(new FlowLayout());
// window.add(panel);
//
// window.setResizable(true);
// window.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// window.pack();
// window.setVisible(true);
new Thread(new Runnable() {
@Override
public void run() {
long t1 = 0;
long t2 = 0;
int p = 100;
int r = 10;
for (int k = 0; k < p; k++) {
t1 = System.currentTimeMillis();
for (int i = 0; ++i <= r; webcam.getImageBytes()) {
}
t2 = System.currentTimeMillis();
System.out.println("FPS " + k + ": " + (1000 * r / (t2 - t1)));
}
}
}).start();
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Video Frame Rate - Top 10 Questions - Gumlet
3. Why does video frame rate matter? · How realistic do you want your video to be? · Do you plan on using...
Read more >The Frames Per Second Question - MeltTools
First, slow the balls down to 50 px/s. Notice the background – it does appear more lifelike at 48 fps than 24 fps....
Read more >Frame rate | Algebra I Quiz - Quizizz
Play this game to review Algebra I. what is the frame rate if 50 frames pass in 2 seconds. ... 10 QuestionsShow answers....
Read more >Some questions on frame rates. : r/gamedev - Reddit
I know that variable frame rates are now the norm in 3D PC games, but are there any noteworthy examples of modern games...
Read more >newbie frame rate question - Gearspace.com
I've asked the director what the final destination frame rate will be and to provide me a video at that rate ... My...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @neilyoung 😄
Indeed, the quantum uncertainty may be to blame, and it may be actually caused by a different quantum states of electrons in the CPU due to the corresponding wave function:
But in your specific case this is much simpler to explain. You see, when you take a look on how
WebcamPanel
is implemented, you may notice aThread
running in background which constantly invokesgetImage()
and renders it on a screen. This happens with maximum FPS rate to have as smooth preview as possible.Now add next thread to the solution (the one from your example), so we have two threads now. Because
getImage()
is blocking by default, these two threads are fighting for access time. Since both have exactly the same priority, JVM gives 50% of access time to first one, and 50% of access time to the second one. Do you see connection here? 100% of access time is 30 FPS (max what your camera can give), then 50% is 15 FPS, and when you add one more thread this will drop down to 33%, which is 10 FPS:You may ask: if this is true, why the hell I see 30 PFS displayed in preview? This is because preview displays FPS of camera, not the thread which capture image. If you sum FPS from all threads then you will get ca. 30 FPS.
Solution? Yes, there is and it’s fairy simple. You have to make
getImage()
non blocking. This can be done by doingwebcam.open(true)
which will open webcam in a asynchronous (non-blocking) mode. But please note that this will only work forgetImage()
, not forgetImageBytes()
.I have to think about a way of how you can make
getImageBytes()
non blocking and will come back to you later.@sarxos Thanks for your patience. Will try to check that out later