How do you track an object and plot its motion against time?

22 Ansichten (letzte 30 Tage)
KLETECH MOTORSPORTS
KLETECH MOTORSPORTS am 21 Dez. 2020
Kommentiert: Image Analyst am 24 Okt. 2022
I'm trying to track the motion of a point on an oscillating pendulum and plot it's displacement versus time graph.
I know i have to : 1) upload the video
2) read each frame
3) track a point on each frame
4) plot the motion of that point w.r.t time
And so far, i've used this:
vidObj = VideoReader('115.2ANGLE.mp4');
vidObj.NumFrames
while hasFrame(vidObj)
frame = readFrame(vidObj);
imshow(frame)
pause(1/vidObj.FrameRate);
end
a=VideoReader('115.2ANGLE.mp4');
for img = 1:a.NumFrames;
filename=strcat('frame',num2str(img),'.jpg');
b = read(a, img);
imshow(b);
imwrite(b,filename);
end
But all this does is tell me how many frames there are.
The video in question is: https://imgur.com/ZytKDKd and i need to track the black dot on the white, oscillating part.
I've already accomplished this using tracker software, and i'd like to get a graph similar to this one, (which i got for an initial displacement of 24 deg)
Any idea how i can do the same in matlab?

Antworten (1)

Image Analyst
Image Analyst am 21 Dez. 2020
You need to segment each frame to find where the object(s) is/are. Maybe you can do this by threholding or imbinarize(). I'd try these steps (untested)
% Convert to gray scale
grayImage = rgb2gray(frame);
% Crop frame to get rid of white window to the right.
grayImage = grayImage(:, someColumn : end); % You need to determine the column
%========================================================
% First find the white paddle.
% Threshold or call imbinarize()
paddleMask = imbinarize(grayImage);
% Fill holes
paddleMask = imfill(paddleMask, 'holes');
% Take largest blob only. That's the white paddle
paddleMask = bwareafilt(paddleMask, 1);
% Find centroid of white paddle.
props = regionprops(paddleMask, 'Centroid')
% Get x and y
xPaddle(frameIndex) = props.Centroid(1)
yPaddle(frameIndex) = props.Centroid(2)
%========================================================
% Now get the black dot.
blackBlobs = grayImage < someThresholdValue;
% Erase junk outside the paddle
blackBlobs = blackBlobs & paddleMask;
% Note, black dot might not be resolved enough to find it!
% Take largest blob only. That's the biggest black dot.
blackBlobs = bwareafilt(blackBlobs, 1);
% Find centroid of black dot.
props = regionprops(blackBlobs, 'Centroid')
% Get x and y
xDot(frameIndex) = props.Centroid(1)
yDot(frameIndex) = props.Centroid(2)
frameIndex is what you misleadingly called "img". It's not an image, it's a loop interation counter/index.
  8 Kommentare
Sara K Takiguchi
Sara K Takiguchi am 24 Okt. 2022
Hi i am using this code for my project on 2021b Matlab and getting this error code:
Intermediate dot '.' indexing produced a comma-separated list with 12 values, but it must produce a
single value when followed by subsequent indexing operations.
Error in motiontrackingandplotting (line 60)
xPaddle(frameIndex) = props.Centroid(1);
Do you know what this means and how to fix it?
Image Analyst
Image Analyst am 24 Okt. 2022
Your segmentation probably didn't find any blobs so props is empty.
If you have any more questions, then, in a new thread (not here), attach your data and code to read it in with the paperclip icon after you read this:

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Mathematics and Optimization finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by