Some background:
I'm building an AR art installation, and need to track a person as they move through a room.
To do this I've built a head piece that has several infrared lights (with diffusers) and have a camera (a USB webcam) that has an optical filter to remove most/all visible light from the image, as well as a few tweaks to the image that basically leave me with white dots on a black background.
Getting the webcam set up in such a way as to capture the boundaries of the room was pretty easy, but I'm unsure as to how to go about then processing the black and white image to get the x,y coordinates of each dot.
Example image output: (This is a mock-up as I don't have one on me this second, and also keep in mind that the data will come from what is effectively a video)
Tools I'm using
- NodeJS for processing
- Logitech Webcam for image capture
- Google Cardboard for visuals
- Infrared leds in styrofoam balls for nice diffuse light points
Any ideas?
I can think of three ways to do this with ImageMagick, which has
node
bindings, and is installed on most Linux distros and is available for OSX and Windows.First, at the command line, quite simply type this:
and that shows you the three brightest pixels are 146 pixels across from the top left corner and 164 pixels down from the top left corner, and the two beside it to its right.
Alternatively, if you are interested in the area and/or centroid of the dot, you can do a Connected Components Analysis with ImageMagick, which goes like this:
This shows you (in the last line of output) that the white blob is 11 pixels x 11 pixels and is located 143 pixels across the image from the left edge and 164 pixels down from the top. Its centroid is at 148,169 and its area is 97 pixels and its colour is white.
The first object found (in the second to last line of output) is the entire image and you can discount that as its colour is black, i.e. rgb(0,0,0).
I can explain the parameters a little too... I convert to grayscale because Coonected Component Analysis traditionally looks for white objects on a black background in a b&w image. I then threshold to get pure white and pure black - you may need a median filter here on your real system to get rid of noise
-median 3
, for example. Theverbose=true
means that the command should print a list of all the blobs it finds, and the8
means to consider pixels that are 8-connected to be parts of the same blob, i.e. a pixel touching another one at its NE, SE, SW, or NW corner is considered part of the same blob - if you set that to4
, pixels have to be directly beside or above/below one another to be considered neighbours.If you want to "box in" the area that it has found, you can do that like this:
The third method is slower, and it involves converting the image to text and then searching for the word "white". So. let's start simple, and just convert the image to text like this:
Now, let's refine that, and look for white pixels only (on Windows you would use
FINDSTR
rather thangrep
):As regards a
node
version, I am really not very good atnode
but I can point you to my answer here which does another ImageMagick process throughnode
and hope you can adapt that if you try the above at the command line and find it works for you well enough that you want to use ImageMagick.