CamShift Object Tracking (Composition by Peter)

Author: Peter
License:
Date: 2012.06.17
Compatibility: 10.6, 10.7
Categories:
Required plugins:
CVDetection Plugin

This sample composition demonstrates the CamShift object tracking method.

In this example an initial Haar detection will be performed to define the tracking area which get passed over to the CamShift tracking. The tracking results are send through a Kalman filter to stabilize and predict the object movement (e.g. when the object is covered or only partly visible).The tracking results will be constantly re-evaluated according to a given threshold and the CamShift parameters automatically adjusted.

Still a lot of work in progress and plenty to optimize...

The attached CVDetection.plugin will need to be copied to (your user folder)/Library/Graphics/Quartz Composer Plug-Ins first

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

benoitlahoz's picture
Re: CamShift Object Tracking (Composition by Peter)

Must be great ! Thanks for sharing. Unfortunately it crashes on main thread on my MBP 13", with 10.7.3. Here are the details (I have a cvError on line 9) :

Process:         Quartz Composer [466]
Path:            /Developer/Applications/Quartz Composer.app/Contents/MacOS/Quartz Composer
Identifier:      com.apple.QuartzComposer.editor
Version:         4.5 (144)
Build Info:      QuartzComposerEditor-144000000000000~3
Code Type:       X86-64 (Native)
Parent Process:  launchd [126]
 
PlugIn Path:       /Users/USER/Library/Graphics/Quartz Composer Plug-Ins/CVDetection.plugin/Contents/MacOS/CVDetection
PlugIn Identifier: HelloWorld.CVDetection
PlugIn Version:    2.4 (2.4)
 
Date/Time:       2012-06-19 11:00:30.658 +0200
OS Version:      Mac OS X 10.7.3 (11D50)
Report Version:  9
 
Crashed Thread:  0  Dispatch queue: com.apple.main-thread
 
Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
 
Application Specific Information:
objc[466]: garbage collection is OFF
terminate called throwing an exception
abort() called
 
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib           0x00007fff87305ce2 __pthread_kill + 10
1   libsystem_c.dylib                0x00007fff849f67d2 pthread_kill + 95
2   libsystem_c.dylib                0x00007fff849e7a7a abort + 143
3   libc++abi.dylib                  0x00007fff82b8d7bc abort_message + 214
4   libc++abi.dylib                  0x00007fff82b8afcf default_terminate() + 28
5   libobjc.A.dylib                  0x00007fff842b51cd _objc_terminate + 114
6   libc++abi.dylib                  0x00007fff82b8b001 safe_handler_caller(void (*)()) + 11
7   libc++abi.dylib                  0x00007fff82b8b05c std::terminate() + 16
8   libc++abi.dylib                  0x00007fff82b8c152 __cxa_throw + 114
9   HelloWorld.CVDetection           0x00000001122b0e4a cv::error(cv::Exception const&) + 746
10  HelloWorld.CVDetection           0x0000000112362587 cvIntegral + 1703
11  HelloWorld.CVDetection           0x000000011238d1b8 cvHaarDetectObjectsForROC(void const*, CvHaarClassifierCascade*, CvMemStorage*, std::vector<int, std::allocator<int> >&, std::vector<double, std::allocator<double> >&, double, int, int, CvSize, CvSize, bool) + 5272
12  HelloWorld.CVDetection           0x000000011238ed54 cvHaarDetectObjects + 116
13  HelloWorld.CVDetection           0x0000000112141af9 -[CVDetectionPlugIn(Execution) execute:atTime:withArguments:] + 1060
14  com.apple.QuartzComposer         0x00007fff84c16641 -[QCPlugInPatch execute:time:arguments:] + 143
15  com.apple.QuartzComposer         0x00007fff84b11709 -[QCPatch(Private) _renderAtTime:arguments:] + 145
16  com.apple.QuartzComposer         0x00007fff84b11661 -[QCRenderingManager addPatch:context:time:arguments:nextExecutionTime:] + 3273
17  com.apple.QuartzComposer         0x00007fff84b0ffee -[QCPatch(Private) __execute:arguments:] + 918
18  com.apple.QuartzComposer         0x00007fff84b0fbc7 -[QCPatch(Private) _execute:arguments:] + 2149
19  com.apple.QuartzComposer         0x00007fff84b108c3 -[QCPort _execute:arguments:] + 377
20  com.apple.QuartzComposer         0x00007fff84b0fa57 -[QCPatch(Private) _execute:arguments:] + 1781
21  com.apple.QuartzComposer         0x00007fff84b10634 -[QCPatch(Private) _executeSubpatches:arguments:] + 297
22  com.apple.QuartzComposer         0x00007fff84b10504 -[QCPatch(Extensions) executeSubpatches:arguments:] + 57
23  com.apple.QuartzComposer         0x00007fff84b104be -[QCPatch(Customization) execute:time:arguments:] + 41
24  com.apple.QuartzComposer         0x00007fff84b1043d -[QCPatch(Customization) nextExecutionTimeForSubpatches:time:arguments:] + 167
25  com.apple.QuartzComposer         0x00007fff84b1034e -[QCPatch(Customization) nextExecutionTime:time:arguments:] + 73
26  com.apple.QuartzComposer         0x00007fff84b102d5 -[QCPatch(Private) _nextExecutionTime:arguments:] + 665
27  com.apple.QuartzComposer         0x00007fff84b0ff9a -[QCPatch(Private) __execute:arguments:] + 834
28  com.apple.QuartzComposer         0x00007fff84b0fbc7 -[QCPatch(Private) _execute:arguments:] + 2149
29  com.apple.QuartzComposer         0x00007fff84b0daf2 -[QCContext nextExecutionTimeForPatch:time:arguments:] + 476
30  com.apple.QuartzComposer         0x00007fff84b0d910 -[QCGraphicsContext nextExecutionTimeForPatch:time:arguments:] + 39
31  com.apple.QuartzComposer         0x00007fff84b0d71f -[QCOpenGLContext nextExecutionTimeForPatch:time:arguments:] + 476
32  com.apple.QuartzComposer         0x00007fff84bcb45d -[QCView nextExecutionTime:arguments:] + 76
33  com.apple.QuartzComposer.editor   0x000000010a04eac3 0x10a03f000 + 64195
34  com.apple.QuartzComposer         0x00007fff84bcafbe -[QCView render:arguments:] + 450
35  com.apple.QuartzComposer         0x00007fff84bcb72e -[QCView _renderTimer] + 396
36  com.apple.QuartzComposer         0x00007fff84ba1f9a _TimerCallback + 79
37  com.apple.CoreFoundation         0x00007fff81a73c24 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
38  com.apple.CoreFoundation         0x00007fff81a73776 __CFRunLoopDoTimer + 534
39  com.apple.CoreFoundation         0x00007fff81a54001 __CFRunLoopRun + 1617
40  com.apple.CoreFoundation         0x00007fff81a53676 CFRunLoopRunSpecific + 230
41  com.apple.HIToolbox              0x00007fff8c65d31f RunCurrentEventLoopInMode + 277
42  com.apple.HIToolbox              0x00007fff8c6645c9 ReceiveNextEventCommon + 355
43  com.apple.HIToolbox              0x00007fff8c664456 BlockUntilNextEventMatchingListInMode + 62
44  com.apple.AppKit                 0x00007fff8b563f5d _DPSNextEvent + 659
45  com.apple.AppKit                 0x00007fff8b563861 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 135
46  com.apple.AppKit                 0x00007fff8b56019d -[NSApplication run] + 470
47  com.apple.QuartzComposer.editor   0x000000010a041a41 0x10a03f000 + 10817
48  com.apple.AppKit                 0x00007fff8b7deb88 NSApplicationMain + 867
49  com.apple.QuartzComposer.editor   0x000000010a040d3c 0x10a03f000 + 7484

Peter's picture
Re: CamShift Object Tracking (Composition by Peter)

Thanks for the info.

Unfortunately I am unable to reproduce this under 10.7.3 (Quartz Composer 4.5 (141.5).

It seems to crash during the initial Haar detection but I cannot pinpoint just yet why. Do you have any other OpenCV plugins loaded which might interfere?

dust's picture
Re: CamShift Object Tracking (Composition by Peter)

your example runs fine for me in 10.7.4.

any chance on sharing your source with me ? dustin.oconnor@me.com your cv projects interest me peter. actually so does your blob tracker @benoitlahoz so the same goes for you as well on the blob tracker.

i got this working as per your example which was needed. i like the idea of the haar tracker defining an initial region for the cam shift. are you building a cascade on the fly with the cvdetection ? i have been getting interesting results without cvdetetion as well or at least better results than the cam shift cv example. kudos.