File Exchange

image thumbnail

Human Action Recognition using KTH Dataset

version 1.0.0.0 (19.5 MB) by Manu BN
A Matlab code to recognize human actions

38 Downloads

Updated 20 Apr 2016

View License

A Matlab code is written to recognize human actions namely 'walking', 'jogging','running', 'boxing','hand waving', and 'hand clapping' using Spatio Temporal Interest Points (STIP) and classify the same using a KNN classifier. Please download the KTH Action recognition dataset from the link http://www.nada.kth.se/cvap/actions/ and put them in the folder KTH Dataset folder.
How to run ??
1. Place the 'Action Recognition Code' folder in the Matlab Path, add all the folder and subfolder to the path
2. Run Recognize.m
3. Select a video from the KTH Dataset
4. Observe results
The code is loosely based on the paper below, please cite and give credit to the authors:
[1] Schüldt, Christian, Ivan Laptev, and Barbara Caputo. "Recognizing human actions: a local SVM approach." Pattern Recognition, 2004. ICPR 2004. Proceedings of the 17th International Conference on. Vol. 3. IEEE, 2004. ftp://ftp.nada.kth.se/CVAP/users/laptev/icpr04actions.pdf
Suggestions and comments are always welcome
Thanks in advance,
Manu B.N

Cite As

Manu BN (2019). Human Action Recognition using KTH Dataset (https://www.mathworks.com/matlabcentral/fileexchange/55111-human-action-recognition-using-kth-dataset), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (151)

Nisar Bahoo

Sir you gone the great work. it is really help full for me as i am looking to do my Final Year Project in this topic. your code helped me alot but sir i am facing a error

Undefined function or variable 'TrainFeat'.

Error in main1>Recognizedaction_Callback (line 120)
X=TrainFeat;

Error in gui_mainfcn (line 95)
feval(varargin{:});

Error in main1 (line 43)
gui_mainfcn(gui_State, varargin{:});

Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)main1('Recognizedaction_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.

sir can you plz help me about it, i shall be very thankful to you.

Bashid

Sir I have tried to run the recognise.m file but I'm getting error like
implay([pathname,filename]);

Hello,sir.Can you send me tranning project. Thankyou verry much( Email:khacdatnguyen9x@gmail.com)

xuyuan

Thanks very much,sir.But it seems some problems.The one when I run main.m and I got this error: Unable to read file 'Trainfeature'. No such file or directory. Another one is that the code can only classify cycling and surfing.I am very confused.

YANG LEI

hello,sir.Could you send me the training .m files? Thank you (My email: 15733513567@163.com)

Sir can you please send me training data? Email: rohitssnal@gmail.com

what is the exact command for confusionmat?

Undefined function or variable 'TrainFeature'.
Error in main1>Recognizedaction_Callback (line 80)
X=TrainFeature;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in main1 (line 20)
gui_mainfcn(gui_State, varargin{:});
Error in
@(hObject,eventdata)main1('Recognizedaction_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback

i am getting this error . how do i resolve it?

Can you please send me the code? My email is: ammarsirine3@gmail.com

Hello sir, I want to recognize unusual activities like falling, crawling & suffering. How it can be done?

Can you please send training.m and test.m files? Email id junaidibrahim90@gmail.com

Can you please send training data.mat file ? Email id foram89833@gmail.com

Can you please send me the code?Email: foram89833@gmail.com

Priya HE

sir, how many frames are divided for 1 second in your code.
Is there any constraint to upload a new video which is not trained.
please mail the solution at priyahe66@gmail.com

Shruthi H K

sir can you please tell me how to recognize the action from the new video which is not included in the trained dataset????
sir please send me the solution to this mail hkshruthi15@gmail.com

Bhushan Deo

could you please send me algorithm at : anu.kulkarni1919@gmail.com

River Wang

Could u please sent me the training.m file to my email. (1208211893@qq.com)

Plz sent algorithm my emailid :prashantpatel22222@gmail.com

Thanks for the code.I have a doubt that where did you use the temporal Information in the code for extracting the STIP points

thanks, I want to ask you what is meaning of matrix meas in TrainFeat.mat
can you please help me?

thanks, I want to ask you what is meaning of matrix X in TrainFeat.mat
can you please help me?

Akash Hegde

when I run the recognize.m, I got this error. Can you help me to solve it? thanks

Error using imwrite (line 467)
Unable to open file "Frames\11.jpg" for writing. You might not
have write permission.

Error in Recognize (line 24)
imwrite(mov(k).cdata,['Frames\1',num2str(k),'.jpg']);

Moussa BA

I run main.m and I got this error: Unable to read file 'Trainfeature'. No such file or directory.
Can you give the file train.m please, my email is: emb5828@umoncton.ca, thx you!

It works, you have to check the Type variable for the classification results @Jane Hui

Jane Hui

I have run the "Recognize.m". It can successfuly recognize cycling and surfing. However, If I choose another video, it does't work. Did someone else meet the same problem? Or, somebody kind can help me.

Guys That was a very beautiful piece of code from @Manu BN
Great work Manu.
I am just trying to give my understanding over the code to clear the confusion here, a bit.
The Code can run any on any test video from KTH(Single human action recognition) dataset.
In Recognize.m File You can see the Type = predict(md1,Z); so obviously TYPE is the variable you have to look for obtaining the confusion matrix among the 8 class. and unfortunately when i run the code "Running" is the only action which has been recognized with an accuracy of 50%. All the other actions are mostly miss-classified as Surfing.
And i hope this is because of extracting the features on frame level since i can see the test variable is an 50x1 dimension varaible, which is to my understanding that only 50 frames are considered for classification during the training.but this code worked as a little dynamite to my study over action recognition.
The code works on all the videos in the KTH dataset, the final pop-up doesnot appear since the classifiaction results are so sparse. But still you can get the recognition accuracy of the test video in the Type(50*1) variable. which in turn shows how many frames are classified correctly from 50 input frames.
In Case if u need more accuracy over actions you train the classifier with more input data/ Clip level data with a little change of the code provided here.
Thanks Manu,
It would be very helpful if u perform clip based classification with different appearance and motion features like MBH/HOF, it would be a noble contribution.
Great work Bro!!!

Jane Hui

Thank you for your code! I' ve just run. It worked. But it seems that the code can only classify cycling and surfing. I was wondering if the .avi name has special meaning. It prints out "surfing"because the video name is 8? That makes me confused. Perhaps I should have a deep think. All in all, thanks.

can you please send me the code?(email: swdwmsribaglary14@gmail.com)

please send me train.m file to harshs613@gmail.com

sathiya

kindly send me the code to sathiysavi@gmail.com

Thanks in advance

Lucy

Could you send me the training .m files? Thank you (My email: 1215110906@qq.com)

Mce

hasan molla

what is the function of maxsupression.m

can you send me train.m file ..pls my email is harshs613@gmail.com

while running the code following error occurs.
"Undefined function or method 'VideoReader' for input arguments of type 'char'."
can you help me in this regards
Thanks in advance

Great work! Can you send me the training.m files? Thanks in advance (my e-mail: volkanulutas@gmail.com)

Can you send me the training,m file, please?
My email: Famirous.Fam@gmail.com
Thanks in advance
@Faisal imtiaz This is my email I would like you to end me a training.m file, please?
Thanks in advance

Could you send me the training .m files? Thank you (My email:gzdenrgz001@gmail.com)

Wishakha

I want to extend this project for some other activities.Can you please explain how the training can be performed?

Manu BN

@ Santosh: Plz go thro all the comments & description. I have placed links to description
@ Mohanad: STIP is the feature set
Thanks to all for the rating

can u provide me the resources,which are useful to understand the code !

email-id : santhoshbijinemula@gmail.com

Thank you ! :) !!

Wishakha

which features did you used for classification ,in general bounding box area and centroid is it enough to distinguish between each activity in kth video ??

Could you send me the training .m files? Thank you (My email: 402986395@qq.com)

Fatttouma

AMIT

hello Manu,
this code is really a great help for me in my work.
I just want to know how you create the trainfeat matrix and also what feature you use for it.
Thanks and Regards

Manu BN

@ Wei Jie: You are correct about everytinh man. Thanks for the rating

Can you send me the train.m file? My email : 13bscsmusman@gmail.com

Todd Mobley

I'm on a mac and experiencing the same issue as one person below. If I run "Recognize" on videos 7 and 8 (already in the KTH dataset folder), it outputs the correct action. If I run the code on any of the 6 ((DivX-compressed) videos, it outputs the frames, but no action (running, jogging, etc)

Thanks for sharing code. That helpful for my work! Some Questions as following:
1.About the feature abstraction function STIP. Can you detail or explain the meaning about parameters and returns.[posinit,valinit]=STIP(f1,kparam,sxl2,sxi2,pointtype,nptsmax);

2. About the training dataset constructing: I choose a "video clips" for sample, then use "STIP" function to abstract the features (40 dimensions/valinit), and assign a label to this sample. Is that's OK for my understanding?

3. The sample is "video clips" (has 50 frames) not just "a frame picture"?

4. As for 'TrainFeat.mat', it has 50 samples per class?

In a word, that's a fantastic work for me!!! Thanks again!

Lee Seah

And bro for the code u provided i able to follow these few step( select a video-> frame conversion-> preprocessing ->corner detection->pruning) but when i click for show me the result it show error. May i know what error is that?

Lee Seah

Could you send me the training .m files? Thank you (my email: leeyuseah@gmail.com

Manu BN

@ Faisal: It works perfectly. You have to wait until the pop up window appears
@xuxiansheng, Huy: Train.m can be created by reading all the frames from a video file and storing the features in a .mat file and next give a label 1,2 etc based on the classes and save it. Use the same method of feature extraction that I have done here.
@ Leek: Only 6 videos from the link mentioned. For others train it yourself.
For detailed explanation of feature set go thro youtube links mentioned in one of the below comments
Thanks to all for the ratings

Huy Pham

Could you send me the training .m files? Thank you (My email: huyulsan@gmail.com)

leek Luo

I can't figure out the use of harrislpls.m. Could you please explain a little?Also, after reading all the comments, I'm still wondering if you use the whole KTH dataset to train your classifier or only used 6 sample video to train your classifier?I can recognize 2 upload clips 7.avi,8.avi and 6 sample avi you mentioned and others would fail.Did I mess up something?Thanks.

xuxiansheng

@Faisal imtiaz My email is peizenxu1@163.com.wo can Communication with it.

@xuxiansheng i can share you the .m for training set,testing with using a single frame in a video and taking whole video as a single entity ,result... improvement in detection of result and improvement with classifier

xuxiansheng

i have read the all comments,but i still don't know how to train the other dataset.why not have the train.m.

The end result have decision playing but i am unable to find ,predict type that marked as playing

Sorry for multiple comments and multiple ratting,please all remove repeated comments

code is good,for training,Is valinit from test saveda and 400 training set are created?How can new type be added for predict?

code is good,for training,Is valinit from test saveda and 400 training set are created?How can new type be added for predict?

code is good,for training,Is valinit from test saveda and 400 training set are created?How can new type be added for predict?

FAS

Manu BN

I suggest u go thro all the comments below as the same question was asked by many ppl

xuxiansheng

Thanks for your reply.Only the six sample sequences can be recogniticed.why the others can not be ? I want to train other database,how can i do it

Thank you for your code. I run the code and I got this error "Undefined function or variable 'meas'. Error in Recognize (line 54)X = meas ,if you don't mind plz help me to solve this problem

Manu BN

@xuxiansheng: Type value will be based on the label assigned to the videos. Are u downloading the KTH with 6 videos and not the others ones available in same website.

FAS

xuxiansheng

i have run the code again.When I set a breakpoint,i find the "Type"value is not consistent.so it has not output.When i choose to output the most of the value.NO matter i choose the walking,jogging or boxing it will output surfing.only when i choose the running it can recognitice.Can you tell me why?Thank you!

Manu BN

plz go thro all the comments below

xuxiansheng

Thank you for your code.but i have some questinos.when i chose the "7.avi or 8.avi",it can recognition .when i chose the KTH dataset it can not output the stytle.can you tell me why? thank you

xandratom

Curiosity: In the STIP function, where are temporal directions taken into account?

Manu BN

I have trained it using KTH. If you want you can try Weizman Caltech etc. Use the same procedure for feature extraction.

xandratom

Is it possible to have more information about the training dataset? Or has the classifier been trained on the KTH dataset itself?

Manu BN

Go thro all the comments below.... you will understand

xandratom

Ok, actually problem solved. It was a format problem, caused the Video Reader function on Macintosh. As soon as I moved to Windows, no problem. At least on the datasets suggested by you, but the code doesn't seem to work on videos that I manipulate.

xandratom

I have the same problems that other have: the code apparently is not working with the downloaded videos. I don't understand why, since the format and the dimensions are correct. I am pretty sure I am doing nothing wrong, actually.

Manu BN

Its the exact implementation !!!

Aliyu

Thanks Mr Manu for sharing you code. I am wandering how I can extract the HOG and HOF directly using your code as implemented by Laptev?

Manu BN

If you can go through Dr. Laptev's paper and maybe watch his video
https://www.youtube.com/watch?v=mbd_k7XARmg.

Its more than sufficient to understand HAR

dear all, where can i get literature abt. the code. I want flowchart of processing and complete information reg. all functions used in the code in relation with the flowchart.

Manu BN

@Dongxu: method for extracting the features for training is same as the one given here for testing. You just have to assign a label and save it using 'save' command.
thanks to all for the ratings.

Dongxu Gao

Do you also provide the code for getting the "TrainFeat.mat"?

Venkat R

Very useful submission

Tyou

Manu BN

Use one vs all approach for evaluating accuracy. The Matlab command 'confusionmat()' will plot it. main.m is not the file, Recognize.m is.

how you are testing for accuracy and calculating confusion matrix ? and how i can use your gui when i opened main.fig and load the video it gave me errors ? thank you

hiep ga

you can lead a more detailed way is not? thank you very much

Manu BN

Train it and assign the label and save using 'save' command in Matlab. Follow the same procedure for feature extraction as in the recognize.m

jia lu

how can i add new video to this?? and the new video should also 256*256 right??

hiep ga

If I download the data in zip files then I I have to do to recognition. plz help me. thanks

Manu BN

Pretty soon I will come up with a documentation and a tutorial for training. I just checked , it works perfectly for hand clapping.

could you please add a documentation for the code and the parameters of the function? , and the classifier works fine for all the KTH dataset except handclapping

Manu BN

The paper gives a very detailed description of spatio temporal interest points, plz go thro it first. If you want further details watch video by Dr. Laptev himself: https://www.youtube.com/watch?v=mbd_k7XARmg.
Videos lectures by Dr. Mubarak Shah also give an awesome explanation.
Regarding training a classifier: first workout basic examples using Fisher Iris etc. and go thro this code, you will get ideas to train on your own. Plenty of online tutorials are also available.

Thank you so much for the code.
It works perfectly on Matlab 2013a with correct predicion. However it is kind of a blackbox for us..
How did you train the classifier? Can you please explain the working procedure behind it and the use of the main files in the project?
It would be really helpful for me..
Thanks again!

Manu BN

I will make a video of how to run and paste the link here ASAP. Plz wait for few more days. The code is working correctly on KTH.

Manu BN

You need to download tha Divx files , not the ones in zip.
Come on.... this is the 5th time i'm checking but the code is working perfectly in Matlab 2013. The pop up and the command window results are appearing perfectly.

Dear Manu,
Neffati is right, its working on your given videos in uploaded file. its not working on KTH dataset.

I’m sure that the code is working, I’m just not getting what I am doing wrong here

Manu BN

Download the 6 videos from the link and put it in the folder. The code has more than 100 downloads/month i'm quite sure you are making some mistake. Once its broken to frames, in few seconds a pop up dialogue box will tell the type.

Thank you sir for updating the code.
When I apply the code on the two videos found with the updated version (cycling / surfing) it works perfectly, but when I try to apply it on one of the videos of the KTH dataset it does not work: 50 frames appear and that’s it.
The pop up dialogue don’t appear and I do not see any prediction.
I would be thankful if you can help me fix the problem

Manu BN

You need to wait for a few seconds for the pop up dialogue box to appear. i have updated the code.

I have created a folder named 'Frames’ and the code works perfectly I just don’t see any prediction

Manu BN

Please create an empty folder named 'Frames' in the path of the code and then run. I just checked the code again, once the folder is created it works perfectly.

Thank you for sharing this code.
Sorry for the inconvenience but I do not see any prediction of the listed activity, after I select a video from KTH dataset, selected video appears and then 50 frames from that video displayed! I feel like I’m missing something.
No pop up dialogue box showing results, no results appears on command window either.
I would be very thankful if you can help me fix this problem

poineer

For the variable 'Type',it is a vector,which means the 'Type' should be same in 50 frames,the result can be shown correctly.The condition of judgement is a little harsh ?

Manu BN

sure be little more specific

poineer

Thank a lot,I am a graduate student doing academic research about human behavior recognition now. Can you give me some suggestions for this subject?

if you are facing imwrite (file write permission error) then create a folder "Frames" in your folder where "recognize.m" is placed. then run.. I was facing same error but resolved after creation on "Frames" folder.

Hey, i have enabled write permission. It still gives the imwrite error.

Manu BN

imwrite error happens when you dont have write permission. right click on the Matlab installed folder go to properties and enable it to write

getting an error using imwrite

sorry to bother you but I was not able to fully extract .zipx file. Could you send me the file at sawsen.ghabri.s@ieee.org

Hi, sorry for the inconvenience. I tried but could not solve the problem. It would be appreciated if you send me your code that you are working on. Thanks

Manu BN

I'm quite sure you are making some mistake. I just checked the code again, it's working perfectly. In fact this is the only working code in Human Action in whole of Matlab Central.
Thanks for the rating.

Thanks! I figured it out after asking :) But I have observed that most of the time it predict surfing as an activity whatever the selected video is!!! Did I miss something? It would be appreciated if you explain how to solve that. We can communicate through email (hossain31@yahoo.com) if you want. Thanks in advance.

Manu BN

A pop up dialogue box shows the results, the same can be seen on command window also.

I am new in Matlab. I tried to run this code and it works perfectly but problem is that I do not see any prediction of the listed activity! As instructed, I select a .avi file from KTH dataset, selected video appears and then 50 frames from that video displayed! Is that all? Sorry for my lack of knowledge if I miss something.

Thx a lot .

Done Sir, Thanks a lot for your time and help!

Manu BN

I just checked the code, it is working perfectly.
imwrite error happens when you dont have write permission. right click on the Matlab installed folder go to properties and enable it to write.

I am using Matlab 2015 version. I tried doing it before. I still doesn't work.

Manu BN

First put all the videos in folder 'KTH Dataset', then right click on this folder and select option' add all folders and subfolders'. Then run in Matlab 2013 or higher versions.
Plz rate if possible.

Sir, I tried running your code. It gives an error saying
Error using imwrite (line 454)
Unable to open file "Frames\1.jpg" for writing. You might
not have write permission.
How do I solve this error?

Manu BN

use the latest version of Winzip.

Hey sorry to bother you but I was not able to fully extract .zipx file. Could you send me the file at sorabhtomar@hotmail.com

Manu BN

Thanks for the rating. Plz check out my other projects also.

Man you're a genius! Your code is very nice and elegant. Thanks.

Updates

1.0.0.0

Cycling and Surfing videos are added

1.0.0.0

Links are added for reference

1.0.0.0

Empty forlders Frames and KTH Dataset are added. If you need surfing and cycling videos send an e mail to manubn88@gmail.com

1.0.0.0

Zip files are added as many found zipx files incompatible

MATLAB Release Compatibility
Created with R2013a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Action Recognition Code/html/