How do you track an object and plot its motion against time?
22 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
Image Analyst
2020-12-21
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 个评论
Sara K Takiguchi
2022-10-24
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
2022-10-24
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mathematics and Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!