CVTools Detecting lines after a time

benoitlahoz's picture

Hi !

I'm trying to detect lines from a movie / video input to trigger another movie stuck to these lines.

Actually, when the image is totally motionless it works very well, but a little movement make the Line Detection "panic".

What I would like to do is to wait a certain amount of time testing if there is movement in the image, and then trigger a line detection only once to launch the second movie.

I guess I have these steps to realize, but I can't manage to find how :

  1. testing movement in time
  2. triggering one detection if the image is not moving too much (it can't be really motionless if this is a video input / movie)
  3. storing the line structure
  4. testing again if there is movement. If yes : I delete the stored lines and then restart at point 1.

I wonder how to make a median of velocities values in time. May be with a queue ?

Any idea ?

Thanks a lot in advance !

benoitlahoz's picture
Re: CVTools Detecting lines after a time

Well, I've resolved the time thing with a Queue on N frames and a Javscript to caculate the median, but triggering only ONCE a detection of the lines is still a problem.

I'm using a Watcher and a Conditional to trigger a pulse to a Queue "Filling" or "Reset". But the Queue seems to fill even if the "filling" is set to false...

benoitlahoz's picture
Done with a queue on one image

Done !

For time testing, I used a queue to test the velocities in the 50 last frames, then I send the result (motion or motionless, according to a threshold value) to the line detection patch, where another queue stores only one image for lines to be detected.

I'll post the comp when it'll be finished.

:-)

PreviewAttachmentSize
Capture d’écran 2010-10-30 à 20.21.16.png
Capture d’écran 2010-10-30 à 20.21.16.png199.33 KB

dorijank's picture
looks really cool

nice stuff...cant wait to see where you go with this...

dust's picture
Re: looks really cool

cool haven't played around with lines much. i imagine this could be really interesting if you are using keyed video or video with alpha mask...

i have an opencl motion trigger and velocity macro if your still needing those things. basically you use a before and after frame derived from a queue then calculate the distance between the two frames divide by the time between motion and no motion or vise versa. this gives velocity of movement in video. you can also use delta time or the time in-between the frames your using to detect motion.

to get the hit when there is motion i just subtract the difference between the frames and search pixels for white, when white is found that means there is motion.

jersmi's picture
Re: CVTools Detecting lines after a time

I love this -- nice job! I'd be interested to see the comp.

benoitlahoz's picture
Re: CVTools Detecting lines after a time

Thanks for your comments !

Actually it's all made of adapted kineme users comp ! I shall make a readable and interesting-for-other-users comp then I'll post.

benoitlahoz's picture
Re: looks really cool

Thanks dust.

I'm very interested to see the difference with your system, as mine is really... a tinkering noobz system...

Would you mind posting or sending it ? Thank you !

monobrau's picture
Re: Done with a queue on one image

Nice approach! Will be interesting for mapping projects!

gtoledo3's picture
Re: looks really cool

You can add a smooth to keep your lines from shutting off , or kind of delay them from shutting off. Just a thought. You could also set it so that color fades from white, to alpha black when tracking goes awry (via an rgb patch and smooth with your sprites in over blend), which will make them sort of fade into clearness.

This reminds me alot of something Zuga did a long time ago....tree people, I think it was called.

benoitlahoz's picture
Re: looks really cool

Yes, I'm working on this : fade in and out.

Zuga's work is really really cool and, indeed, is kind of same system I guess. But we are not going the same way. I post the Zuga's video below.

When we had this resarch on shadow with the CNRS (french national research center) we did'nt imagine that shadow was interesting so many people... but it is universal, without frontiers. I guess that's why we are so many to try to investigate its meanings.

Actually, we're working on a spectacle on Haruki Murakami's world. Shadow is omnipresent, like in the whole Japanese culture, as far as I know. You only have to think about Tanizaki.

The work of Philip Worhtington on "Shadow Monsters" is really great and meaningful too... (video below)

gtoledo3's picture
Re: looks really cool

Oh I didn't really mean to suggest that you were directly influenced. It's a very big leap, and very different look, graphically.

What you posted is really cool looking. I guess the other thing to work out (?) would be to tweak which direction the little man is walking in scenarios where the line is mostly vertical. You could probably rig it so that the head of the guy always points to the borders (or vice versa).

You can use the structure sort, say by Y or !Y, (or x, or z), and that may create some interesting effects in the directions that the little guys walk (or it may be horrible! I don't know...)

benoitlahoz's picture
Re: looks really cool

Oh no ! I didn't understand that you were suggesting anything !

Thanks for your posts. That's an honour and so rich to have comments from you all.

I'm influenced by a lot of things, including Zuga and Worthington, influenced by all the comps I'm downloading on kineme. The main thing, as far as I'm concerned, is the meaning of the visuals (and in my case, of the visuals in a scenography, on a stage, with real actors). For me, QC is a tool (incredible tool but tool) and a field of investigation.

I try to finish something readable quickly, and, if you don't mind, I would be very glad to have your advices and comments on the real comp.

benoitlahoz's picture
CVTools Line Mapping Composition

Here it is.

I didn't have the time to find an elegant solution to perform the detection before the first "motionless trigger" for static images to work again.

A lot of work to be done with this comp.

I would be glad to have your returns and/or modifications.

[edit : and would like to choose which lines are interesting / rotate correctly the image inversing the points, as GT adviced. A lot of work !]

PreviewAttachmentSize
Carasuelo_Lines_Mapping.qtz156.74 KB

benoitlahoz's picture
Re: CVTools Detecting lines after a time

Hi !

A new version. Didn't work much on it as I had a bunch of work on an other side.

I put a Structure Range on the Lines Structure, and copied an old version, plugged it to de/multiplexers to have a still image lines detected.

Not very elegant... :/

I tried to work with GL Quad too, to have the quads distort and touch the border of image (sorry for my poor english, don't know if it is understandable).

What I would like to do now is to get the lines coordinates make "rays" from the tracked shadow, and displaced by it. I must study again the Bernardo's 3D Vector comp.

I have to precise that this is aimed to be applied to a real time shadow we produce with one of the shader we made with the CNRS. It's difficult to work without the possibility to test the specific rhythm of a living body ! :) I should have recorded other moves inside the screen... Next time !

By the way, this post offers me an occasion to thank everybody here for the bunch of comps, researches and advices... and the good mood ! I began with QC in may (well... in august) and this is a big fantastic world that's opening in front of my eyes. Thank you for the glasses !

PreviewAttachmentSize
LineMapping+Movie.zip1.71 MB

Scratchpole's picture
Re: CVTools Detecting lines after a time

Your example video looks great. Is this composition 10.6 only? No luck running it in 10.5 for me :(

(null) : Patch with name "/instructions" is missing

Macro Patch Cannot create node of class "/instructions" and identifier "(null)"

Macro Patch Cannot create connection from ["output" @ "Splitter_3"] to ["_enable" @ "Patch_8"]

Macro Patch Cannot create connection from ["MedianInTime" @ "Patch_6"] to ["Text" @ "Patch_8"]

(null) State restoration failed on

benoitlahoz's picture
Re: CVTools Detecting lines after a time

Instructions Patch is not very important. Can't you run it without it ?

[edit : and, I'm sorry but as a noob in QC AND Mac (I know it's a lot of noobzies) I don't know the difference between 10.5 and 10.6... ]

dust's picture
Re: CVTools Line Mapping Composition

here is that motion detection patch i was talking about. it might help, i usually connect a smooth to the motion logic. sort of delay the hit as it is very responsive. also i included a sort of average x y of the motion to get some coordinates and the monochrome image. not sure if it will help or not.

benoitlahoz's picture
Re: CVTools Line Mapping Composition

Thank you dust ! But... I guess you forgot to post the file.

Or am I blind ? :-)

dust's picture
Re: CVTools Line Mapping Composition

oops, this uses open cl. so it may work or not depending on your system. if it doesn't i have a few other ways of doing this...

PreviewAttachmentSize
motionDetection.qtz21.73 KB

cybero's picture
Re: CVTools Detecting lines after a time

10.5 = Leopard = less fully 64 bit than 10.6 | 10.6 = Snow Leopard = more fully 64 bit & has some new patches, including Instructions patch that basically does what would otherwise have required an Image with String and a Billboard or Sprite in 10.5 or < in QC.

So I guess you could put those in place of the 10.6 dependent patch, however, upon asking the composition to display compatibility information, it would seem that in fact it raises alarms starting with the Movie Importer patch and running through to Sprite, Detect Lines macro, Display Background Image, Sprite, Walking Shadows, Instructions & Lines.

By the Way, Forum Meister, please see the attached screen grab - bit of an ImageMagick problem to report - totally unrelated, but the Grab [odd-kineme-forum-message.jpg] is attached at 72 dpi.

PreviewAttachmentSize
odd-kineme-forum-message.jpg
odd-kineme-forum-message.jpg64.79 KB

benoitlahoz's picture
Re: CVTools Detecting lines after a time

Thanks for the explanation ! I didn't understand well where the problem can be from with the Movie Importer patch...

NB : I have the same "Image Magick" report.

benoitlahoz's picture
Re: CVTools Line Mapping Composition

Thanks so much ! I'll try with you patch asap.

cybero's picture
Re: CVTools Detecting lines after a time

Quote:

I didn't understand well where the problem can be from with the Movie Importer patch...

No doubt due to the differences between 10.5's and 10.6's QuickTime [QuickTime X in 10.6] ; Movie Importer utilising the underlying framework in either OS versions.

jersmi's picture
Re: CVTools Line Mapping Composition

Hey Dust, could i talk you into saying a little more about how your motion detection patch is supposed to work? Like, what is the data being sent from the mapping patches? If i hook maps up to x/y pos on a sprite and image out to sprite image, it gives me blinking pixel lights jumping around my screen but i can't really follow what it's supposed to be detecting, ie, the "average" of what? Also, do you think the openCL would be stable enough in a performance environment?

dust's picture
Re: CVTools Line Mapping Composition

ok the image output is used only if you need velocity map in image format. it doesn't really serve a purpose other than some plugin like particle warfare can take a motion image and generate particles from the velocity image for example. its not really needed.

the main useful component output is the hit. this is derived from the motion velocity image. basically the kernel here is outputting a monochrome structure of pixel values.

seeing that you can not output a scalar value from a cl kernel. scalar meaning not a structure. the js patch is used to sum up an average mean that can be then be used as a scalar input to a conditional patch.

basically just checking, if there is "white in the image" if so there is movement and give me a hit. this is pretty sensitive so i find useful to delay the truth with a smooth patch.

now the mapping function is just an interpolation js macro i find useful. its here in the repository under "mapping function." ok granted this part of the patch is pretty hard to follow.

so let me explain. first off just to detect motion a high res image is un called for. so by using a small image of size 10x10 we keep our pixel structure small and easy to manage.

the second kernel takes the size input of the image 10 x 10 and makes a positional map by assigning the size of the image to two different threads. normally this is used read in an image to cl kernel as it is needed in order to iterate pixel by pixel. i don't really know why i split this up into two kernels ?

ok so we now have two structures one with the velocity map pixel data and the other with just position data. now this is the tricky part i iterate through velocity map pixel structure just like i did when getting the hit value but this time i'm not using an average. i'm checking pixel by pixel for white when there is white i add the index to queue to mark the position on the screen where there is motion.

so the monochrome image is just a 1d structure of pixel data. so by queueing up the monochrome structure with a size of 10. i am able to check row by row for motion if there is motion i forward the index to the positional structure which i can derive an x and y coordinate of where the motion is.

you will see the output of the iterator has a structure index it is set to 0. this means it will report the first instance of motion it finds. if you set the index to 4 it will sort of give you the middle area of the motion between the first instance of motion and the last instance of motion.

after that i'm just using the screen dimensions and math to convert the 10 x 10 pixel grid to qc units. the mapping macro is to compensate the subtle difference in screen size etc.. when mapping pixel dimensions to units its not always -1 to 1.

so i really just use this trigger something when there is motion. if you want to visualize the x y of your motion. set the index from iterator out to maybe 4 to get the not the first instance of motion but the 5th and then attach the xy to some smooths and a circle. and you will see the circle jump around to where on the screen there is motion velocity.

i mean you can do all this with open cv but with open cl its really fast. so there isn't much latency.

oh yeah as per the production environment safety of this open cl kernel its entirely safe as a friend of mine has been running it for days non stop in a public environment. so as long as you don't change the grid size to the cl kernel it should run indefinitely. open cl doesn't like changing its size particularly when its running.

jersmi's picture
Re: CVTools Line Mapping Composition

okay, thanks so so much for the explanation. i need to sit with it for a bit. the openCL stuff is different. so i hear you that it's fast, but is it stable do you think? for ex., with benoitlahoz's animation lines patch in this post mixing open cv with the open cl? how about edge detection with openCL?

benoitlahoz's picture
Re: CVTools Detecting lines after a time

Hi there !

Coming back after a long time on this topic.

I can't manage to fade in/out my shadows on these lines and it would be a tremendous help for me to have advices on this point.

What I would like to do is to control each of the "lined images" to make them fade in or out at the time I want them to (kind of God stuff... :-))

Thanks so much in advance for your advices (I know everybody is on the Kinect right know but well...) :-)))

jersmi's picture
Re: CVTools Detecting lines after a time

I'm following this post. No time right now to look at it, but maybe you could create a queue for alpha fade values outside the iterator, then use current index and structure index member inside the iterator to assign value(s) to alpha with interpolation or the like.

leon's picture
Re: CVTools Line Mapping Composition

Thank you for posting this nice patch and explaining its logic. I wonder why I have no output in X and Y, and motion logic. Maybe CVtools is not longer compatible with capitan?

leon's picture
Re: CVTools Line Mapping Composition

Thank you for posting this nice patch and explaining its logic. I wonder why I have no output in X and Y, and motion logic. Maybe CVtools is not longer compatible with capitan?

leon's picture
Re: CVTools Line Mapping Composition

Thank you for posting this nice patch and explaining its logic. I wonder why I have no output in X and Y, and motion logic. Maybe CVtools is not longer compatible with capitan?