We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey guys ! I'am trying to modify code for motion detection from Dan's tutorial:
In his original code, he is comparing current frame only with the previous one. What I'am trying to do is comparing current frame with the average frame of two previous frames (actually I'am taking 99% pixel value of pre-previous frame and 1% pixel value of previous frame. It should make detection more accurate). I edited "captureEvent" function so it can load second frame and added new "GetFrame" function which takes two frames as argument and returns an average frame. In theory it should work but it doesn't and I only get gray, empty window. What did I screw up ? I know code is a little bit long but I suspect mistake to be in "GetFrame" or "captureEvent" function.
EDIT: I have problem placing code here using markers in editor so Iam pasting it from pastebin: https://pastebin.com/jkBuex0v
Answers
EDIT:
Here is how to format code for the forum:
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text
Capture event is an event -- when it gets called, there is only one video frame to read.
Here is one long-form way approach to what you might be trying to do:
starting up:
continue:
There is also a more efficient method of doing prep, which only requires one buffer image (not two) and the current frame to accomplish your previous-two-blend:
Thx for the reply ! First of all I want to run it, then I will think about increasing efficiency. Secondly I fixed the captureEvent function and now it should load frames properly. From 3rd iteration pprev, prev and video are getting new frames in proper order. Also I noticed that the problem is caused by GetFrame function. Commenting it makes everything works fine. So I have to focus on that I guess. Here is the actual code:
I'm confused. The code you posted doesn't call
captureEvent()
anywhere...?You need to revise your code. I don't think you are averaging two previous frame but you are including your current one. Your code should look like this:
Also notice line 68 is being called inside a nested loop. But
GetFrame()
is made of the same nested loop concept. Move line 68 outside and above the nested loop.I didn't solve the post because I am not clear of what you are doing at the end of draw() and how you are using the comparison PImage object. Hopefully these tips drives you to your solution.
Kf
@jeremydouglass As I understand, captureEvent() is run automatically whenever new frame is available. https://processing.org/reference/libraries/video/captureEvent_.html
So, GetFrame function was useless. Also as You said I didn't need the "comprasion" frame. Iam now simply calculating new color values basing on pprev and prev frames. But its still not working corectly. Its detecting motion without motion and always drawing circle near the center. I dont know why. rc = 99/100*r1 is almost the same color (pixel) as r1 (line 77,78,79) .