Objects
So far our program has just been detecting motion in general, but in order to use this program for our rig we needed to output more information about what we had detected. There are many sources for movement in an image, like wind blowing on a tree in the background. We needed to filter out those kind of movements as they are just noise to us. To be able to do this we had to implement a routine to separate the motion in a frame into different objects.Separating objects are done during the processing of each image. This processing occurs pixel by pixel throughout the entire image. A routine is called every time a changed pixel is detected. The location of this pixel is then checked against the border of the existing objects to see if it is close enough to be part of the object.
The images below illustrates the processing of a image where a changed pixel is detected and appended to an existing object.
If no object is within range of the changed pixel there will be created a new object to house it. The limits for how near two pixels have to be can be adjusted, but a test with a distance of 2 gave good results.
Object center and vector
When the image is fully processed the method outputs a list of objects detected. These objects are then checked by size. The largest object is considered the most important and is prioritized for further processing. The other objects are discarded to save memory.
The center of this object is the found by the following formula:
And the object center is then used to calculate the vector from the object to the middle of the screen, by using this formula:
The resulting vector can then be used further down the road to control the motors on the rig.
These images are the actual output of the program:
Black/white (white signals movement):
And color:
No comments:
Post a Comment