I am trying to track my hand based on the area using Media Flow Tracker but the bounding box keeps increasing after some time. It works properly for the first 10 seconds or so.
Here's a code snippet:
def main():
display = SimpleCV.Display()
cam = Kinect()
ts = []
bb = None
img = cam.getDepth().flipHorizontal()
while display.isNotDone():
depth = cam.getDepth().flipHorizontal()
filtered = depth.stretch(0, 180).binarize().dilate(1)
if bb is None:
blobs = filtered.findBlobs()
if blobs:
hand = blobs.filter(abs(7000 - blobs.area()) < 500)
print hand
if hand:
bb = hand[0].boundingBox()
print bb
if bb is not None:
ts = filtered.track("mftrack", ts, img, bb)
if ts:
ts.drawBB()
ts.showPixelVelocityRT()
ts.drawPath()
filtered.show()
For tracking, we pass the current frame to the existing multi-tracker object. If tracking is successful, we extract the new box coordinates with which to draw rectangles around the previously detected objects and print the corresponding class labels, on the current frame.
I would remove the call to dilate
from the following line:
filtered = depth.stretch(0, 180).binarize().dilate(1)
From the SimpleCV documentation:
dilate(iterations=1) Apply a morphological dilation. An dilation has the effect of smoothing blobs while intensifying the amount of noise blobs. This implementation uses the default openCV 3X3 square kernel Erosion is effectively a local maxima detector, the kernel moves over the image and takes the maxima value inside the kernel.
The variable filtered
is used each loop iteration with filtered.findBlobs()
. The intensity and density of these blobs are used to determine dimensions of the bounding box.
You are calling the stretch
function along with dilate. Over time, the call to dilate
leads to noise being detected as part of the hand, so the bounding box increases accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With