File Exchange

image thumbnail

Particle Filter Color Tracker

version 1.7 (12.5 MB) by

Tracking an object in a video with a Color Particle Filter

4.71429
23 Ratings

52 Downloads

Updated

View License

A simple example demonstrating how to track an object with particle filter. Likelihood function is based on Bhattacharya distance of color histograms and gradient distributions

Please run mexme_pf_color_tracker to recompile mex-files on your own plateform.

Run the two demo files test_pf_colortracker and test_pf_colortracker2

IMPORTANT. Be sure than you "mex -setup" had been done before compiling sources

Comments and Ratings (83)

EKC

EKC (view profile)

Running R2015b (64bit Windows) on my new PC. Had to replace mmreader(video_file) with VideoReader(video_file) but getting:

Error using VideoReader/init (line 619)
The file requires the following codec(s) to be installed on your system: cvid.

Any ideas how to fix?

FYI mmreader() & all code worked fine on my old PC (running 32bit R2011).

Any ideas?

Jigar Mori

This code is not working as expected. Can you have complete MATLAB implementation?

I am working on "Parameterizable FPGA framework for particle filter based object tracking in video". It uses histogram and bhattacharya co efficient. Can anybody suggest MATLAB code so that I can replicate on VHDL.

Huang Bo-Yang

Ahmad

Ahmad (view profile)

Hello Sir,

well, once again thanks for such a marvelous code that has indeed helped a lot. Sir, I was just wondering to test a hybrid tracker that is based on PF and meanshift (MS) optimization technique which is a gradient based search mechanism that is responsible for the evaluation of the particles at hand.

Sir, I am going into a kind of error that I think results from the corruption of the HEAP and as a result my Matlab exits with ACCESS VIOLATION ERROR.

But when I restrict the MS to just one iteration (contrary to the average in MS which is 5). So the bottom line is that MatLab crashes when I increase the number of MS iterations.

could you please give me any clue that would save me much of the time. Thanks

regards
Ahmad

fu yun

fu yun (view profile)

I'm very grateful for your excellent work.It's really helpful!
And I have a question : how to set the color I need to track? Eg:I want to track a red object,where should I set the parameters? How to change the files?

Ahmad

Ahmad (view profile)

Ahmad

Ahmad (view profile)

The desperation worked out at last ... I only Uncommented the pdfgrad_ellipse function with a threshold_grad in the input list (which was by default commented) AND I Commented the pdfgrad_ellipse function without threshold_grad in its input list .... my statement might be confusing so have a look at the 2 functions that were played with ....

likelihood_shape = pdfgrad_ellipse(Z , yk , ek , h0 , lambda , sigma_shape , l , alpha0 , ratio , bary , nb_classe , threshold_grad);

% likelihood_shape = pdfgrad_ellipse(Z , yk , ek , h0 , lambda , sigma_shape , l , alpha0 , ratio , bary , nb_classe);

payal

payal (view profile)

Thanks a lot for sharing this code...
Thanks Ravi Prakash, without settings you mentioned I was unable to do it...
Thanks a lot...

payal

payal (view profile)

Sebastien PARIS

Ahmad,

Did you recompile mex files for your system ? (run mexme_ ....).
What is your exact OS ?, compiler ?

Ahmad

Ahmad (view profile)

Sir, I mean test_pf_colortracker is tracking fantastic BUT the test_pf_colortracker2 is making the trouble ... and I have used BREAKs in my code (I mean your code :)) .. and I have identified the error making function which is the pdfgrad_ellipse ....
Thank you very much sir for the quick response .

Sebastien PARIS

Ahmad,

What do you mean by "the second part of the code" ? Does the tracking is well displayed ?

Ahmad

Ahmad (view profile)

Thank you Sebastein for sharing this code, I am having problems with the 2nd part of the code. Matlab forces me to restart it, am I doing something wrong.
Configuration of my systems are:
core-i5, 4 GB RAM, Windows 7 Home edition, SDK 7.1 installed, MatLab 8.2.0.701 (R2013b) .... Sir, can you look into this issue please. I shall be thankful Sir, Regards

Sebastien PARIS

Jae,

Please find informations in:

X. Rong Li et V. P. Jilkov : Survey of maneuvering target tracking. Part I. Dynamic models.
Aerospace and Electronic Systems, IEEE Transactions on, 39(4):1333–1364, 2003.

Jae Hyuck

Firstly, thank you for this excellent program.
While analyzing this program, I got a question.

When you construct motion model covariance matrix for pos and vel, R_y, you consider them as dependent(not using diagonal matrix) as a relation with delta_k. Could you give me some evidence why you select such model?
% R_y = sigma_y |delta_k^3/3 delta_k^2/2|
|delta_k^2/2 delta_k|

Stendo

Stendo (view profile)

Sebastien,
You know how it doing ?

Sebastien PARIS

Stendo,

You must define a model of likelihood given your geometric model of your object... and plug into this code

Stendo

Stendo (view profile)

Hi please help me.I would need to modify this project. I need to recognize objects using geometric properties or edge recognition. It must be particle filter. I am a beginner in MATLAB and I do not know how to do. Thanks for helping
s.bogdan@pobox.sk

daher

daher (view profile)

Hi all
I am having an inquiry. Suppose i have to track the first blue color object found in a video. After few frames, another object with the same color appears. How to keep tracking the first object no matte what will appear in the video without referring to the geometry of each blue object and compare it with the first identified. Hope you can give me a hint... Thaaaaaanks

Ricardo

Excellent, thank you. Still have to fully understand the theory though :)

Users of Linux hope this helps: video_file should be set to the full path, e.g. '/opt/matlab/.../SECOND.AVI', and have gstreamer0.10 plugins installed.

If you do not have mmreader, check out mmread from fileexchange. mmread does not instantiate a class, it returns a struct and therefore all set, get, read in the original test files should be replaced to access struct members.

ln38:
video = mmread(video_file);
nb_frame = video.nrFramesTotal - offset_frame - 10;
dim_x = video.width;
dim_y = video.height;

ln127 : I = video.frames(offset_frame + 1).cdata;
ln158 : I = video.frames(offset_frame + k).cdata;

i get problem with file download. can you help me for send me the file at my email please? vitalokaa@yahoo.com

balaji

balaji (view profile)

thanku sir..

Sebastien PARIS

K Nummiaro, E Koller-Meier, L Van Gool, An adaptive color-based particle filter, Image and Vision Computing, 2003 - Elsevier

for example

balaji

balaji (view profile)

sir i need some details about this pf colour tracker..any reference paper about this example?

Excellent code. Works perfect on my Win 8, Matlab 2011b x64. Can you please cite the paper you used for writing this tracker?

GITAM

GITAM (view profile)

waiting for u r valuable reply

ECE

ECE (view profile)

cool

sahere rahimi

i do not have any c compiler, please help me, please give me a file that does'nt need any c compiler

Sebastien PARIS

Ching-Chun: 2009b win64 ?
Can you put a break point to stop at errors ?

Ching-Chun

I change the matlab version to 2009b, however the error still occurs. I hope I can help to repair the bug, but there is no more information.

Sebastien PARIS

The problem ... that I don't know from which mex-files, the crash is coming....
Do you have more verbose ?

Ching-Chun

sorry, I forgot to mention these. My Os is windows 7 64-bit, processor is Intel Core 2 Duo 2.80 GHz, Matlab version is 7.6.0.324 (R2008a), and the used compiler is Microsoft Visual Studio 2010.

Sebastien PARIS

What is excetly your system ? OS, processor, version of Matlab, compiler used ?

Ching-Chun

Sebastien Paris, thank you. The program works well now. But when I run "test_pf_colortracker2.m", there are some errors and then Matlab asks to restart. Is it because I do somethin wrong? The followed are excerpts from the error messages:

...
Frames = 106/770
Frames = 107/770
Saving minidump to file C:\Users\irene\AppData\Local\Temp\matlab_crash_dump.4692.0.dmp

------------------------------------------------------------------------
Segmentation violation detected at Mon Mar 05 15:20:34 2012
------------------------------------------------------------------------

Configuration:
MATLAB Version: 7.6.0.324 (R2008a)
MATLAB License: 161051
Operating System: Microsoft Windows Vista
Window System: Version 6.1 (Build 7601: Service Pack 1)
Processor ID: x86 Family 6 Model 7 Stepping 10, GenuineIntel
Virtual Machine: Java 1.6.0 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
Default Encoding: Big5

Fault Count: 1

Register State:
rax = 00000000ffffffff rbx = 0000000000000028
rcx = 000000000000ef53 rdx = 0000000000000011
rbp = 0000000000000029 rsi = 0000000000001d3b
rdi = 00000000354f5cd0 rsp = 000000000102bc00
r8 = 0000000000000000 r9 = 0000000000000028
r10 = 000000003547e228 r11 = 0000000000000028
r12 = 000000000000000b r13 = 000000003da57e00
r14 = 0000000000000000 r15 = 00000000000000fa
rip = 000007fef8291c93 flg = 0000000000010203

Stack Trace:

This error was detected while a MEX-file was running. If the MEX-file
is not an official MathWorks function, please examine its source code
for errors. Please consult the External Interfaces Guide for information
on debugging MEX-files.

... ...

Sebastien PARIS

Ching-Chun. As indicaded in requierements, you must have C compiler. Please install for example Visual C++ express accoding to your version of Matlab.

Ching-Chun

Please help me.
What should I do to make it works?

When I compile the file "mexme_pf_color_tracker.m"
I got the messages

echo on

mex

Select a compiler:

[0] None

Compiler:

If I enter "0", I got more messages as follows.

mex: No compiler selected. No action taken.

**************************************************************************
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:
http://www.mathworks.com/support/solutions/data/1-5C27B9.html?solution=1-5C27B9
Building with the -largeArrayDims option enables the new API.
**************************************************************************


C:\PROGRA~1\MATLAB\R2008A\BIN\MEX.PL: Error: No compiler options file could be found to compile source code. Please run "mex -setup" to rectify.

??? Error using ==> mex at 207
Unable to complete successfully.

Error in ==> mexme_pf_color_tracker at 3
mex

zhao

zhao (view profile)

Hi Sebastien,i modified the files,and Create more problems. If i want to run the files in matlab7.0, can you sent the right files to me. My email:happyday.huihuang@gmail.com,thanks a lots.

Sebastien PARIS

Zhao,

Instead of badly rating, please have the nominal configuration requiered.

zhao

zhao (view profile)

zhao

zhao (view profile)

My matlab7.0 can not find function 'mmreader'. If aviread is used,can tell me where should be replace in the files.
thanks

Can anyone explain me how to install the C compiler and compile the C files in MATLAB..

Hi Sebastien:
I am new to this can you explain how to execute.I m getting error like C file is not found.I think that because of the mex compiler. how to install that with brief.Is it necessary to install VC++ 2008 express.Can I run it in Matlab2011.

Chi Chin

Hi Sebastien,

Thanks for your prompt reply. I had installed the K-lite mega codec in my system but it still give me the same error :<

Sebastien PARIS

Chi,

Maybe install a video codec pack such K-lite mega codec in your system. Regards,

Chi Chin

I get the following error on Windows 7(64-bit) and MATLAB R2009b. Can anyone assist?

??? Error using ==> aviread at 76
Unable to locate decompressor to decompress video stream

Error in ==> test_pf_colortracker at 196
mov = aviread(video , offset_frame + 1);

anyone can help me?

Selva

Selva (view profile)

Thanks for sharing dude..

Sebastien PARIS

oj: If I have time, I'll update with mmreader instead of the old (and depreciated) aviread

Sebastien PARIS

Jake: here IS used here is independant of the current measure so ... q(x_k|x_{k-1},z_k) = p(x_k|x_{k-1}) here ...

oj

oj (view profile)

Dear sebastien I am unable to get the program in running condition... Even though I have replaced mmreader for aviread... still cudnt fix problem... help anyone..

Jake

Jake (view profile)

Thank you for sharing, I just wondering did you pick a importance density in this program?

Sebastien PARIS

to kar: as we say in french "pour avoir le beurre et l'argent du beurre".... in other words, the easiness of matlab and the speed of C.

tejaswini kar

sir can i get the reference material of the codes for my work.actually i am unable to understand it.is it possible that either the whole program can be written in matlab or written in c.why u have used both c an matlab. what is the advantage.

Kevin Murphy

tarun goel

Hi sir, it is indeed a nice work and thanx for sharing it. Could you please tell some refeence material where the meaning of variables can be understood as their names are of little help. Iwud be highly thankful.

Duy Nguyen

Duy Nguyen

Thank for your sharing, Sebastien. I want to get more detail about this issue, can you give me reference for this ones.

Hong 4

Hong 4 (view profile)

I found a paper relates to this subject:
K Nummiaro, E Koller-Meier, L Van Gool, An adaptive color-based particle filter, Image and Vision Computing, 2003 - Elsevier

Hong 4

Hong 4 (view profile)

I found a paper relates to this subject:
K Nummiaro, E Koller-Meier, L Van Gool, An adaptive color-based particle filter, Image and Vision Computing, 2003 - Elsevier

Yong Zhao

thanks for you sharing, I'll study and discuss with all of you.

Janayna

did you use any paper to implement the particle filter?
Thank you

Fang-I Chu

can i ask if i want to track a moving object under grayscale, what is it different from color tracking?

yasong guo

i have solve it now!thank you for your codes .wonderful!thank you!!!

Sebastien PARIS

Ok, you can replace the aviread function with the new one 'mmreader' to read avi files.

M

M (view profile)

I get the following error on Windows Vista (64-bit) and MATLAB R2008b. Can anyone assist?

??? Error using ==> aviread at 76
Unable to locate decompressor to decompress video stream

Error in ==> test_pf_colortracker at 196
mov = aviread(video , offset_frame + 1);

PS: I tried installing CINEPAK, but it didnt work! :(

Tedo Biresaw

Wow! what really a nice work.
I get it work.

Sebastien PARIS

Ok, I'll update with a mexmefirt.m file for mexfilers beginners

Thx all for comments/ratings

Ravi Prakash

For all those laymen like me who couldn't get it to work in the first attempt. Type inside the MATLAB command window

> mex ellipse.c
> mex rgb2hsv_mex.c
> mex pdfcolor_ellipserand.c

In both files part_moment.c and particle_resampling.c at the top add the line
#define max(a,b) ( (a) >= (b) ? (a) : (b) )

Then
> mex part_moment.c
> mex particle_resampling.c

Finally to run
> test_pf_colortracker

Thanks Sebastien. FIGHT ON!!

Got it to work. Thanks

I'm having some trouble recompiling with the part_moment.c file. It says there is an undefinded reference to '_max'. Can you help me please.

XU FENGLIANG

thanks for you sharing

min hu

thanks for program.it is very good.

nauha jam

Thanks for program.I would ask about the LAB model of color image in matlab

prabhakar raj

i want the code for tracking faces in an image sequence using particle filter,can u help me in this

li jackey

how to recompile mex files?when the file is compiled in VC platform,the problem is always that mex.h can't be found,how to deal with it ,please tell me quickly,thank you

ophelka flowerfairy

to recompile simply use
mex filename.c

Sébastien Paris

Please recompile with the following command :

mex -output rgb2hsv_mex.dll rgb2hsv_mex.c

loi yii tien

Actually i am doing the object tracking in video using neural network. Can you send me an example of it if you can do it. Thanks!

loi yii tien

How to recompile each mex files? and i got error...

??? Invalid MEX-file 'C:\Program Files\MATLAB71\work\pf_colortracker\rgb2hsv_mex.dll': The specified procedure could not be found.

.

Error in ==> test_pf_colortracker at 202
im = rgb2hsv_mex(Z);

hope to hear u soon!

loi yii tien

How to recompile each mex files?

Tom Pinkiewicz

It works now and it looks excellent. Well done!

Sebastien PARIS

You are right. I have just update with the missing file. Thx you....

Tom Pinkiewicz

The C files compiled okay but I get an error that function part_moment is undefined. Are you missing a file with this function?

Updates

1.7

-add #define max & min for LCC compiler

1.6

-Add likelihood based on gradient distribution
-Use mmreader instead of aviread

1.5

-Add Linux64 with GCC support

1.2

-Minor changes

MATLAB Release
MATLAB 7.5 (R2007b)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video