Directional trigger for blob movement in live video feed? Match obj not working.
Trying to set up a trigger for directional movement detected from a live video feed.
Currently I have cv.jit blobs detection coupled with an lkflow object that only displays movement. A bang is triggered whenever the left or right side of the video frame detects a moving form (people walking in front of the video camera). There's a separate bang for each side, left and right. The bangs send a message for each side, "L" for left and "R" for right. I then tried to use the MATCH object to logically filter the results "LR" and "RL" so that I can have a separate trigger for people who walk through the video frame left to right, and a separate trigger for people who walk through the video frame right to left. It works somewhat but it creates a glitch after the first trigger: the last letter of the previous sequence is used as the first letter of the new sequence, i.e. after "LR" bangs, it holds the "R" to use next, so that if "L" is triggered next, it bangs "RL". Here, the sequence "LRL" bangs twice, once for "LR" and once for "RL". I need it to bang only when a new two letters are given, so I introduced a dummy letter "X" hoping that it would act to clear the slate for the next sequence. Every time a two letter sequence "LR" or "RL" is banged from MATCH, it also bangs an "X" back into MATCH, so that the sequences are broken up, i.e. "LRXRLXRLXLRX..." etc. However, in execution, it only works in one way: starting with "L", an input sequence "LRLR" works, it only bangs twice, once for each sequence of "LR". But starting on "R", it doesn't work, a sequence "RLR" bangs twice times, at "RL" and at "LR" and then the sequence is "reset" to only bang for "LR" now, so a continuation starting on "R", i.e. "RLRLRL", bangs once for "RL" but then only for the following "LR"'s, starting with the very next "R". I'm not sure why it only works one way, because the logic is identical for both "LR" and "RL" type MATCH inputs.
It seems overly complicated in this written description, but if you try it in the patch it should be pretty clear.
Could anyone tell me why this is happening, suggest a way to fix it or offer a different way for me to either create a logical gate for LR/RL or a completely different way for me to get the same result for triggering separate bangs depending on horizontal blob direction?
*(Attached is the full patch "timeisafourletterword" and a patch of just the MATCH objects logic gate "matches".)
why not use numbers to represent your regions instead of letters? You could just use the x or y data if you have that as well. Then use [change +] and [change -] to determine if the numbers are increasing or decreasing and thus if the blob is moving left or right. Let me know if this is helpful.
Grizzly, thank you for responding! I tried to figure out the change object but couldn't wrap my head around it properly. I discovered that my original way works if the dummy "X" is pressed manually in between, leading me to a work-around involving a line object delay of about 1/10 of a second. Apparently the dummy "X" was getting sent too quickly, though I'm not sure why there needs to be a delay, especially of that length of time, because at first I tried only 1 milliseconds and then 5 and 10, but that still was too quick. Anyway, I think it now works well enough for my purposes.