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

1

9

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()
Injection answered 21/6, 2015 at 5:45 Comment(0)
P
3

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.

Pantechnicon answered 3/7, 2015 at 3:57 Comment(8)
I will give it a try and let you know.Injection
I see some improvements but still the same issue.Injection
does the box eventually reach a maximum size or does it grow indefinitely?Pantechnicon
It is unpredictable. I have seen both to happen.Injection
I am awarding the bounty because of decent improvements but keeping the question open.Injection
let me see if I can help you out here. have you experimented with the stretch boundary threshold? In other words, try changing depth.stretch(0, 180) to depth.stretch(0,120)Pantechnicon
Quite a bit in fact and came to found 180 worked best for me.Injection
Let us continue this discussion in chat.Injection

© 2022 - 2024 — McMap. All rights reserved.