Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Size of BoundingBox/ROI to track object keeps on increasing despite fixed initial size

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()
like image 402
Rahat Mahbub Avatar asked Jun 21 '15 05:06

Rahat Mahbub


People also ask

How do you track an object in Python?

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.


1 Answers

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.

like image 134
ross Avatar answered Sep 21 '22 06:09

ross