cvblob-python cvUpdateTracks wrapper

76 views
Skip to first unread message

Neil

unread,
Jun 9, 2011, 1:39:34 PM6/9/11
to cvBlob
Hi Nate

I have just installed cvblob-python, and have good results using it to
analyse weather patterns.

However, don't seem to be able to use the cvblob.UpdateTracks

Have run the tests in cvblob so pretty sure that is installed
correctly.

Should it work or is it not complete?

I have browsed through the source and seems to me I am passing it
correct objects, but get some error regards boost not knowing how to
deal with some type.

Thought I would just check here first.

Many thanks,
Neil

Nathan Oostendorp

unread,
Jun 9, 2011, 2:24:48 PM6/9/11
to cvb...@googlegroups.com
Hey Neil,

You're right -- it is not complete -- but UpdateTracks is in there, and it *looks* sane.

The project I am working on, SimpleCV (http://simplecv.sf.net) doesn't use the tracking -- but if you can give me some code to test it I can figure out what's up and get it working.

You can also check out the SWIG python interfaces in the swig branch -- they are feature complete.

--n

Neil

unread,
Jun 10, 2011, 7:02:18 AM6/10/11
to cvBlob
Thanks, Nate

I have succesfully installed the swig version now. However it appears
there isn't a wrapper for CvTracks only CvTrack and as such
UpdateTracks doesn't appear to work here either

Cristóbal; any thoughts Chris

Many thanks
Neil

On Jun 9, 8:24 pm, Nathan Oostendorp <n...@oostendorp.net> wrote:
> Hey Neil,
>
> You're right -- it is not complete -- but UpdateTracks is in there, and it
> *looks* sane.
>
> The project I am working on, SimpleCV (http://simplecv.sf.net) doesn't use
> the tracking -- but if you can give me some code to test it I can figure out
> what's up and get it working.
>
> You can also check out the SWIG python interfaces in the swig branch -- they
> are feature complete.http://code.google.com/p/cvblob/source/browse/#svn%2Fbranches%2F0.10....

Neil Hart

unread,
Jun 10, 2011, 3:11:26 PM6/10/11
to na...@oostendorp.net, cvb...@googlegroups.com
Hey Nate

Blobs are really coming out nicely, so good work on your wrapper of Christobal's great code.

Found the issue that was causing main problem BUT appear to get a glibc error related to invalid pointer.

I have attached a test script basically copied from the test_tracking.cpp script. Please find attached.

1-UpdateTracks does throw an error

2-checking type of blobs before and after 
cvb.UpdateTracks(blobs, tracks, 5., 10, 0)
shows type of blobs changes to tracks

3- Fix I think: _cvblob.C in line 283 change
b[i->first]
to
t[i->first]
Seems to work now, type doesn't change, blobs stay blobs, tracks get assigned values.

Now a get a glibc error though.

Haven't figure out that bug yet though.

Do you have any ideas? do you think it could be related to your FilterByArea wrapper which you mention may cause sloppy memory management.

Anyway, hopefully get it sort and can contribute the test script to a test_tracking.py for your cvblob-contribution.

Cheers Neil
--
Neil C.G. Hart
PhD Student
Dept. of Oceanography
University of Cape Town

test_UpdateTracking.py
EnterExitCrossingPaths2front_blobs.mpeg

Nathan Oostendorp

unread,
Jun 11, 2011, 12:12:15 AM6/11/11
to cvb...@googlegroups.com
Hi Neil,

Good eye -- that should have been t[i->first] since it was trying to modify the tracks dict, not the blobs dict.  

Unfortunately, I "dict" with it for about an hour this evening and was not able to get past the glibc error you mentioned -- even explicitly copying Track objects when reconstructing the dict gives the same error:

*** glibc detected *** python: free(): invalid pointer: 0x0000000001899ef0 ***

I get it consistently on frame 205.  The wrapping is pretty simple (dict of python objects, extracted to a CvTracks map, then back to a dict of Track objects) -- but somewhere in there a referenced track must be getting destroyed that python wants to free.

I've added your test to the wrapper and applied your patch.  At this point, my suggestion would be to try and nail down where exactly that corruption occurs -- it's a bit of a "if anything would break, it would be there" since the dict gets passed into the function and modified as part of the main loop.

--n

Neil Hart

unread,
Jun 11, 2011, 11:49:34 AM6/11/11
to cvb...@googlegroups.com
Hi Nate

Sadly don't have the know how to work getting the wrap fully functional. This is my first real encounter with C++.

However, develop a hack of a work around in test_tracking.py

# UpdateTracks(blobs,tracks, maxDist2Blob, InactiveFrames, ActiveFrames)
# wrapping of pointers has problem if a track in tracks is deleted within C++ cvUpdateTracks
# work around is keep InactiveFrame big, ActiveFrames 0, so track is never deleted
cvb.UpdateTracks(blobs, tracks, 5.0, 10000, 0)

to avoid holding on to tracks that last only a few frames wrote this utility in __init__.py:

def FilterByLifetime(tracks, Active):
  '''Python throws pointer error when CvTracks list has a member deleted, which deletes a member   from  pythons Tracks dict. Simple fix, set parameters such that a track is never deleted by UpdateTracks can now apply criterion to delete tracks only active for few frames'''
  
  for i in tracks.keys():
    if (tracks[i].active <  Active):
      del tracks[i];


I have attached these files with my suggestions added. I have also cleaned up the test_tracking.py so it can be used readily by others.
I suspect for complex scenes with many (1000's) frames this fix could eat up memory but it'll work for my simple needs.

Thanks again for your interest and help.

Will hopefully be able to share with the group my use of these tools in identifying weather systems in daily data.

All the best, Neil
test_tracking.py
__init__.py
Reply all
Reply to author
Forward
0 new messages