movement detection with openCV

Lango's picture

Hi everyone

What I'm trying to do, a few people in the forums say its easy but I haven't actually seen an example yet.

What I want to do is track movement from a video feed (as in x,y coordinates, amount, direction).

How I tried to do this is

  1. video input
  2. black and white
  3. 1 frame difference blend
  4. remove noise
  5. Shrink image for speed and change to an OpenCV image
  6. auto find points to track (looks for points when I click right mouse button)
  7. Then draw points to the screen so I can see how it is going

From this I hoped to be able to use the points positions as where movement is. Amount of points in an area to determine amount of movement and the average of the points direction for the direction of the movement.

However the 'OpenCV Good Points To Track' patch doesn't behave how I thought it would. I assumed if i had a grey scale image it would work like an edge detection.

But when the entire screen is black it still seems to find points (all_black.jpg). To me this doesn't make sense, how can a black point on a black screen be easy to track. I assumed it would of found no points.

When I make some movement with my hand and click (to auto find points). The points are all on my hand moving (as that is the only non-black part) but after a few seconds they move all over the screen (with_some_movement.jpg). I was expecting them to stay on my fingers.

I'm not 'dissing' the patch here when I say what I thought it would do. The patch is awesome, I'm just thinking i'm using it wrong.

Can anyone please explain what I'm doing wrong? Or perhaps a better way to achieve what I want?

I've attached an image of how my patches are connected (qc_movment_detection_1.gif) as well as the quartz file itself. There is also a zip with everything in it to save some clicks :)

Any guidance would be greatly appreciated !

Cheers

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

cwright's picture
Re: movement detection with openCV

"Good points to track" isn't quite edge detection -- it tries to find corners (edges on both X and Y, and not just points, but regions that are "interesting" and likely easy to follow)

Not sure why it's finding stuff on black -- it's probably subtle noise or something that isn't quite visible in the image (I can't get it to work at all on my machine, so I might be mistaken here).

Vade's done some really cool optical flow stuff that uses GLSL/CoreImage, and is consequently much much faster. OpenCV is not the ideal way to accomplish this sort of operation.

s.rozsa's picture
Re: movement detection with openCV

Hey Lango, you could have a look at this thread: http://kineme.net/Discussion/DevelopingCompositions/OpenCVtracker#commen... I think thet the detection of points on a black screen has to do something with the fact that the identifyed points are "added only once" in the patch. Take a look at the documentation of Chrisw comming with the patch. Here is also a slightly "better" version of the composition mentioned in my thread. It is working "somehow" :-)

Cheers,

Sandor

PreviewAttachmentSize
Archiv.zip1.63 MB

Lango's picture
Re: movement detection with openCV

cwright wrote:
Not sure why it's finding stuff on black -- it's probably subtle noise or something that isn't quite visible in the image (I can't get it to work at all on my machine, so I might be mistaken here).

I was thinking it may be some invisible noise, Thanks for the help!

Why can't you get it to work? Are you missing some plugins?

cwright wrote:
Vade's done some really cool optical flow stuff that uses GLSL/CoreImage, and is consequently much much faster. OpenCV is not the ideal way to accomplish this sort of operation

Sorry, i'm new to the forums. Is Vade a member of these forums? Is this his website http://abstrakt.vade.info/ ? Where could I go to see his work (as in source), it doesn't seem to be on that page.

s.rozsa wrote:
Hey Lango, you could have a look at this thread: http://kineme.net/Discussion/DevelopingCompositions/OpenCVtracker#commen... I think thet the detection of points on a black screen has to do something with the fact that the identifyed points are "added only once" in the patch.

Thanks rozsa. I have been following that thread, though because of the talk about haar I thought it was more about face reconginition.

But looking at you composer file from the thread, and after hooking up the mouse clicks to the necessary parts(explained in the other thread) it seems to do what I wanted . Track only light points and then disappear when it goes black.

I will have a closer look tonight or tomorrow night to work out what the difference is between your file and mine. The one you attached here didn't work for me because I'm missing some plug-ins. I will also try to get that working.

Lango's picture
Re: movement detection with openCV

Hi again s.rozsa

Tried getting your attached quartz composer working, however i can't find the following patches

NIThreshold, NIThreshold_1, Billboard_1, ImageResize_1, ColorControls_1

Do you know how I can get them?

cwright's picture
Re: movement detection with openCV

Those patches are from Noise Industries, probably from their product FxFactory. Not sure if you can get just the CI filters for free....

s.rozsa's picture
Re: movement detection with openCV

Yeah, Chris is right - they are from Noise Industries. And they where free at least at the time i have downloaded the package. But yuo don't really need the treshold filter to check out the composition. Just connect the image output from "Exposure Adjust" to the billboard (to see something) and to the image resize (for recog.). As i said: it is working, but don't expect too much :-)

BTW: Chris, do you have an updated version of that Haar-stuff? You was mentioning something like that in a previous posting...

Cheers,

Sandor

Lango's picture
Re: movement detection with openCV

Thanks for everyones help. I believe I have enough here to work with.

For my original problem of the points picking up black. It was that there were subtle differences in the black, which you couldn't tell by eye, but where there. The 'Exposure Adjust' patch fixed this.

s.rozsa, i notice you use the v002 blur patch. When you go full screen, does the image screw up (don't know the technical term)? It does for me (even from your quartz composer).

I have made a simple composition that is

Camera input -> v002 blur -> billboard.

When its windowed its fine, but if i go fullscreen it gets massive artifacting.

cybero's picture
Re: movement detection with openCV

Recreated your simple composition.

Works fine for me , as I would expect, using an iSight video input either windowed or full screen at minimal blur or maximum blur, with a Billboard set to Width 2 or Height 2 [ Auto height or Auto Width respectively].

What camera are you using as your Video input, I wonder?

If it's an iSight camera, then they are designed to give a video primarily to be used within iChat, although capable of full screen output, they are nonetheless only really capable of running up to 640×480-pixel resolution and then not without some attendant problems image quality wise.

Stretching above 640*480 will result in some degradation of image quality which would have already been pushed to the current rendering limits of that camera.

If your camera is using a smaller than 1/4 inch ccd or has a smaller maximum screen resolution than 640*480 or is using a lower bit value than 24, this could also be a cause of lowering of image quality to the level you would seem to be describing.

360*255 is the typical smaller size of video window that iSight gives fairly good resolution for, at least without strapping additional drivers and codecs, which also seems to increase down that camera's image delay factor.

Ah well, a picture speaks a thousand words :-), so why not post the forum a screen grab of your poorer quality video result?

gtoledo3's picture
Re: movement detection with openCV

Ok, I'm ultra dense here... what exactly is it you're not able to do?

I've never had a prob clicking on a point on say, my fingertip, and having OpenCV track. I have a fun little "et phone home" qtz based on that.

Or are you trying to get it to recognize face/hand and only target that?

On a side note...

All we really need for "cool facial detection stuff" is some kind of ovoid detection that can home in on "blinking eyes" and create a bounding box around the head. Easier said than done maybe?

Lango's picture
Re: movement detection with openCV

cybero wrote:
Ah well, a picture speaks a thousand words :-), so why not post the forum a screen grab of your poorer quality video result?

That sounds like a good idea cybero. But i'll open a new thread to keep things organised and help people in the future that search for it.

gtoledo3 wrote:
Ok, I'm ultra dense here... what exactly is it you're not able to do?

My problem was that the 'OpenCV Good Points To Track' was finding black points on black, which in turned stuffed up my movement detection (shown in my first post's image "all_black.jpg"). It turns out that the patches I was using was not actually making everything black, but slight variations of black.

By using the colour controls -> exposure adjust on my black and white image i was able to get everything that wasn't moving perfectly black. This fixed my problem.

Thanks for everyones help, it was more than I was expecting which is always nice. I believe my original problem has been solved, if anyone in the future has this issue but can't work out how to fix it from this thread feel free to email me, so I can give some help back :)

Cheers

Lango