How do you track a tip of a pendulium and plot its displacement against time?

4 visualizaciones (últimos 30 días)
I'm trying to track the horizontal motion of a tip of an oscillating pendulum and plot it's displacement versus time graph. This y-axis is fixed through the frames.
I know i have to : 1) upload the video 2) read each frame 3) track a point on each frame 4) plot the displacement of that tip vs time
video: https://www.dropbox.com/scl/fi/9kauaf0lxm8i69ru04xsl/FR.mp4?rlkey=mzrt6ffxjli7c30e90ir0bcv6&st=sxodfpxh&dl=0
And so far, i've used this:
close all;clear all;
% read video file; xyobj is an matlab object
%there are files:
filename='FR1-10-2.mp4';
xyobj = VideoReader(filename);
Error using VideoReader/initReader (line 734)
The filename specified was not found in the MATLAB path.

Error in audiovideo.internal.IVideoReader (line 136)
initReader(obj, fileName, currentTime);

Error in VideoReader (line 104)
obj@audiovideo.internal.IVideoReader(varargin{:});
% number available frames
nframes = xyobj.NumberOfFrames-1
% frame rate
framerate=xyobj.FrameRate
vidHeight = xyobj.Height
vidWidth = xyobj.Width
frame(1) = struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'),'colormap',[]);
figure(1)
% Specify the boundary of the region to cut
b3=220;b4=350;
b1=375;b2=640;
xmax=b4-b3;
ymax=b2-b1;
hold on
grid on
xlabel('x')
ylabel('y')
axis([ 1 xmax 1 ymax]);
kk=0;
for k1 = 1:nframes-1,
k=nframes-k1;
k
frame(1).cdata=read(xyobj,k);
oneframe=frame(1).cdata;
oneframecut=oneframe(b1:b2,b3:b4,:); % cut an area with ball only to help for recognition
for jp=1:206,
jp1=jp+50-1;
greenChannel = oneframecut(jp1,:, 2);
[xm,im]=min(greenChannel);
xedge(k,jp)=im;
pedge(k,jp)=xm;
end
%pause(0.1)
end
save FR.pos xedge -ascii
pedge1=cast(pedge,"double");
save FR.val pedge1 -ascii
Your help is really appreciated!

Respuestas (1)

Image Analyst
Image Analyst el 22 de Ag. de 2024
It all comes down to extracting one frame at a time and then segmenting that frame and using regionprops to find the centroid.
See my attached demos on video tracking.
It's a generic, general purpose demo of how to threshold an image to find blobs, and then measure things about the blobs, and extract certain blobs based on their areas or diameters.

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by