how to plot speed graph from centroid of the detected object in image processing ?

Dear All,
i would like to plot the speed of the detected object moving only in the x direction in real time.(Not y direction) so i have tried with the following code but didn't get the appropriate solution. please find the attached code and graph i have sending with this file. the graph is not correct because i didnt understant how to implement the following formula
speed= distance/ time,
how can i modified the attached code to display the detected object and speed of moving object from centroid only in the x-direction as in the attached figure in real time.
hope for your appropriate solution.
Thank you.

 Accepted Answer

Add a third axes control. Then get the object alone by cropping it from the entire image using the object's bounding box and the imcrop() function. Then display the cropped image in the third axes.

4 Comments

Thank you for your idea but i am not suppose to crop the image.
I think displaying one video with the detected object and another with plot showing the speed of that detected object in the same window in real time is different from the croping the image and showing the original and croped image in the same window. i have tried imcrop() from this link http://au.mathworks.com/help/images/ref/imcrop.html
however i didn't get what i am exactly looking for.
cant we plot only speed/velocity of that detected object moving in horizontal direction from the centroid, only co ordinate of x, next to the video which shows the detected object?
When you said you wanted to "display the detected object", I thought you want to display the detected object only - by itself - so that's why I suggested crop. Sure, you can plot the velocity as a line plot. But you're not doing that. You're plotting distance, not speed. Just plot speed instead.
The information that you provided was also very useful and i am using that as well.
Now my concern is , actually i know theoretically how to calculate velocity and acceleration from the distance & time.
Speed = Distance/ time & Acceleration = Speed/ time
But honestly i didn't understand how to apply these formula in Matlab to get the Speed and acceleration in real time.
If you don't mind could you please try to explain with MATLAB command. This might be the simple question but i am struggling to get the appropriate result.
Here is the work up to the date, where the graph are not accurate.
If you don't mind, I would like to request to give idea with Matlab code.
Thank you.
Let's assume 1 object. For each frame you should calculate the centroid location. So now you have x and y vectors. You can also keep distance, speed, and acceleration arrays in your loop over frames.
thisDistance = sqrt((x(frame)-x(frame-1)^2+(y(frame)-y(frame-1))^2);
distance(frame) = distance(frame-1) + thisDistance;
frameTime = toc;
speed(frame) = thisDistance / frameTime; % Frame time is like 1/10 or /130 of a second or whatever. use tic and toc to get exact time.
accel(frame) = (speed(frame) - speed(frame-1)) / frameTime;
and so on.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!