We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all
I'm using processing for object tracking and I've noticed that the actual frames per second at which video frames are captured is around 7 fps instead of the set value of either 15 fps or 30 fps (I've tried both). At first I thought that this may have to do with the time taken to complete each loop of the image analysis but I've checked and it's only around 23 milliseconds i.e. it should be possible to process at least 40 frames per second.
Does anybody know why this is happening and how to fix it? I've read that one of the problems with using webcams for image capturing is that they place an additional load on the CPU - the data I've extracted leads me to believe that the allocation for the webcam is insufficient while the allocation for running my sketch is more than sufficient. If this is the problem, is there a way to solve it?
Thanks Stefan
Answers
Some experiments I had about tweaking captureEvent() + pixels[] + thread("") +
synchronized
:http://forum.processing.org/two/discussion/10986/cv-problems
First, let me say a big thanks for your answer! Second, let me say that I think I should've said that I'm new to processing and programming in Java.
From the code and the links that you directed me to, am I correct that the "synchronized" statement controls the execution of the various parts of the sketch and "notify()" is used to relay when there is a new frame available? I'm having trouble getting my head around what exactly "void post()" does and what "try" and "catch" do.
I spent quite a bit of time last night trying to include the code from your sketch into my application and eventually decided that I should use a simpler sketch for figuring this out. I put together the sketch below (it doesn't work), the intention is that it uses "synchronized" along with a thread to copy the pixels from the camera frame into a PImage (if I can get this working then I should be able to apply it to my sketch with relative ease).
This is actually pretty advanced stuff. For further info go here:
http://docs.Oracle.com/javase/tutorial/essential/concurrency/locksync.html
synchronized
blocks is to protect object states against Thread concurrent access.thread("RGBtoBW");
which runs RGBtoBW().brightness(camPix[idx++])
, "Animation" can'tbackground(bw);
and vice-versa!synchronized
blocks under the watch of the same "monitor" object in a given time.bw.wait();
.bw.notify();
.synchronized
blocks.redraw = true
. :)true
if requestDraw is stilltrue
.https://Processing.org/reference/redraw_.html
There are many methods in Java which obliges us to use them, like wait() for example.
B/c calling them can
throw
exceptions that we have to catch when it happens: :-\"http://docs.Oracle.com/javase/8/docs/api/java/lang/Object.html#wait-- https://Processing.org/reference/try.html
https://Processing.org/reference/catch.html
synchronized
&try/catch ()
blocks! :-bdregisterMethod("post", this);
.Awesome, thanks so much for the detailed response! My actual code does need to modify what was displayed but the first of your two new posts cleared most things up for me!
I have one last question (hopefully), can you explain the use of the "for" loop in your RGBtoBW thread and how it works with the "while" loop? From some experimenting I've done, the "for" loop always yields 0 and without it, the thread only seems to run once?
Thank you again, I really appreciate the support.
for (;;)
loop at:for (int idx = 0;; idx = 0) try {
?while (true) {
is.try {} ... catch () {}
block is inside that "infinite"for (;;)
loop.while (idx != len)
relies on the iterator idx declared @for (int idx = 0;; idx = 0)
.for (;;)
, the internalwhile ()
loop would need to become instead:for (int idx = 0; idx != len; )
:DYup, that's the for loop I was talking about. I think everything is clear for me now. Thanks a ton for all the assistance! I'm looking forward to getting this included in my code, I've been getting bogged-down for over 2 weeks now with this problem.
Sorry, me again...
My code includes events that are triggered by pressing keys and now I'm having trouble including this. I put together the code below as a simple tester for myself. The idea is to use space bar to toggle between snow and the camera.
I had a few println()'s in the code while I was testing but no matter what I did, space bar always ended up being true. Your continued assistance would be much appreciated!!!
Your keyPressed() seems too convoluted for just a simple task of toggling a spacebar!
Here's my tweaked version: O:-)