Question

Hello, i have this matlab code where i have to track a red ball from and...

Hello, i have this matlab code where i have to track a red ball from and uploaded video, and plot its direction in x-y direction

My Question is how can i add x vs time plot and y vs time plot in this code. Thank you

if exist('V','var')
delete(V);
end
clear;clc;

V=VideoReader('video.mp4');

figure(1);
x=[];y=[];
i=1;
while hasFrame(V)
J=readFrame(V);
figure(1);imshow(J);title(['Frame No. ',num2str(i)]);
if (i>=28 && i<=132)
bw=J(:,:,1)>200 & J(:,:,2)<80 & J(:,:,3)<80;
bw=imfill(bw,'holes');
A=regionprops(bw,'Centroid');
x(end+1)=A.Centroid(1);
y(end+1)=A.Centroid(2);
hold on;
plot(x,y,'*k');hold off;
end
i=i+1;
pause(1/V.FrameRate);
end
clc;
delete(V);

[m,n]=size(bw);
figure(2);
plot(x,y);axis ij image;grid on;
xlim([1,n]);ylim([1,m]);
xlabel('X (in px.)');
ylabel('Y (in px.)');

fprintf('Distance travelled in x (px.): %.0f\n', x(end)-x(1));
fprintf('Distance travelled in y (px.): %.0f\n', max(y)-min(y));

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Hello, i have this matlab code where i have to track a red ball from and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • write a matlab code that can plot 3 excel files? this plot know can run one...

    write a matlab code that can plot 3 excel files? this plot know can run one excel file of 20crackf1. clc; clear all; close all; data1=xlsread('20f1','spectrum - PXI1Slot4_ai0','A8:B10009');% Importing excel file x=data1(:,1); y=data1(:,2); plot(x,y); xlim([0 100]); xlabel('Frequency in Hz'); ylabel('Amplitude in g'); title('FFT'); hold on; data2=xlsread('20crackf1','a1','A1:B5000'); x1=data2(:,1); y1=data2(:,2); plot(x1,y1); xlim([0 100]);

  • How can I get my while loop to run until my condition in my if statement...

    How can I get my while loop to run until my condition in my if statement is met? (In MATLAB) clc%clears screen clear all%clears history close all%closes all files format long %Euler's Method %Initial conditions and setup %Projectile motion x=3;%randi(3); y=3;%randi(3); figure('color','white'); plot(x,y,'bo'); hold on wind = (-10 + 20*rand(1)); fprintf('The wind speed is %2.2i\n',wind); v0= input('Initial velocity(m/s): '); a= input('Angle of projection(in degrees): '); a=a*pi/180; h=.01; cd=.1; %cdy=.1; %cdx=(rand*2-1)/2; %cdy=(rand*2-1)/2; m=1.5; g=9.8; %acceleration due to gravity in m/s^2 %td=2*v0*sin(a)/g;...

  • I need help in MATLAB. I'm working on a circuits lab report and I want to...

    I need help in MATLAB. I'm working on a circuits lab report and I want to plot the derivative of an input signal. The circuit is a differentiator OpAmp. It is receiving a triangle wave as an input and should output a square wave. (I've included my existing code.) The output formula is: Vout = -(Rf)*C*(dVin/dt) Where Rf is feedback resistance: Rf = 1*10^6; and C = 1*10^-6. EXISTING CODE: %% This section is copied, and then modified from another...

  • Image 1 is the template that may help to solve this problem and it will serve...

    Image 1 is the template that may help to solve this problem and it will serve as a guidline 81418lab1.m % I. Representation of a sine function using Taylor series [-2pi, 2pi] %% Part 1: Definition t = [-2*pi: .01,2*pi); of t - %% Part 2: Definition of y as a sine function of t -Y[1:length (t)l: %% Part 3: Generation of a plot of t and y figure: plot (t,y) hold on xlim(t (-2*pi) (2*pi) ]) ylim([-2 2]) xlabel...

  • MATLAB code for a double pendulum. Please explain each lines for these codes pls. -------------------------------------...

    MATLAB code for a double pendulum. Please explain each lines for these codes pls. ---------------------------------------------------------------------------- clc close all clear all %---------Parameters------------------------------------------------------ L1=1; L2=1 ; M_1=2 ; M_2=1; G=9.8; %---------initial condition----------------------------------------------- tspan=30; theta1=3; theta1_prime=0; theta2=2.5; theta2_prime=0; y0=[theta1 theta1_prime theta2 theta2_prime]; [t,y]=ode45(@pend, [0 ,tspan],[ 3 0 2 0]); %---position of mass 1 and mass 2---------------------------------------- x1=L1*sin(y(:,1)); y1=-L1*cos(y(:,1)); x2=L1*sin(y(:,1))+l2*sin(y(:,3)); y2=-L1*cos(y(:,1))-l2*cos(y(:,3)); %------visualizing the result--------------------------------------------- figure(1) plot(x1,y1,'linewidth',2) hold on plot(x2,y2,'r','linewidth',2) h=gca; get(h,'fontSize') set(h,'fontSize',14) xlabel('X','fontSize',14); ylabel('Y','fontSize',14); title('Chaotic Double Pendulum','fontsize',14) fh = figure(1); set(fh, 'color', 'white'); figure(2)...

  • Translate this matlab code to python title('Starting Number vs Number of Elements in Seq') ylabel('Number of...

    Translate this matlab code to python title('Starting Number vs Number of Elements in Seq') ylabel('Number of Elements in the sequence in the sequence') xlabel('Starting Number') steps = []; vec = 1:25; for i=1:length(vec) s = []; num = i; while true s(length(s)+1) = num; if num == 1 break; elseif mod(num, 2) == 0 num = num/2; else num = (3*num)+1; end end fprintf('%d = ', i) disp(s) fprintf('\n') steps(i) = length(s); end plot(vec, steps)

  • i got it incomplete sorry I put this by mistake. can this be canceled? 4. Use MATLAB or Scilab to implement linea...

    i got it incomplete sorry I put this by mistake. can this be canceled? 4. Use MATLAB or Scilab to implement linear regression, and plot the points and the curve for the following data sets. x [018 12 27) and y [12345 Input: (copy and paste the MATLAB or Sclab commandin the folowing bax) cic X1-101 8 12 271: Y1-11 234 5] Y-transpose(Y1) for n-1:5 X(n,2)-X1(n) end format long ycalc-S(2) X+S(1); scatter(X1,Y1) hold on plot(X,ycalc) xlabel(X) ylabel(Y) title('Linear Regression Relation...

  • Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current...

    Hello. I need help modifying this MatLab code. This is a basic slider-crank animation. the current program stops the animation and then has the crank move backward. I need the crank to instead to move in full 360 degrees circular motion. Exactly like how a slide-crank mechanism works in real life. thank you and here is the code. %%Code Begins Here%% L1=0.2; L2=0.45; W=0.5; tt=linspace(0,15); for i=1:length(tt)     x2=@(t) L2+L1*sin(W*t);     y2=0;     X2=x2(tt(i));     Y2=y2;     sol= fsolve(@(x,x2,y2) root2d(x,X2,Y2),...

  • Below is the MATLAB code of low-cut shelving filter which can cut the low frequency of given music signal and low-boost...

    Below is the MATLAB code of low-cut shelving filter which can cut the low frequency of given music signal and low-boost shelving filter which can boost the low frequency of given music signal. Design your low-boost shelving filter and low-cut shelving filter to have noticeablly different sound. Compare the sounds of two music signals after filtering, and explain the difference in sounds briefly. If there are any mistakes in code, correct them.   Low-cut shelving filter code: close all, clear all,...

  • MATLAB code starts here --------- clear T0=2; w0=2*pi/T0; f0=1/T0; Tmax=4; Nmax=15; %--- i=1; for t=-Tmax: .01:Tmax...

    MATLAB code starts here --------- clear T0=2; w0=2*pi/T0; f0=1/T0; Tmax=4; Nmax=15; %--- i=1; for t=-Tmax: .01:Tmax T(i)=t; if t>=(T0/2) while (t>T0/2) t=t-T0; end elseif t<=-(T0/2) while (t<=-T0/2) t=t+T0; end end if abs(t)<=(T0/4) y(i)=1; else y(i)=0; end i=i+1; end plot(T,y),grid, xlabel('Time (sec)'); title('y(t) square wave'); shg disp('Hit return..'); pause %--- a0=1/2; F(1)=0; %dc freq C(1)=a0; for n=1:Nmax a(n)=(2/(n*pi))*sin((n*pi)/2); b(n)=0; C(n+1)=sqrt(a(n)^2+b(n)^2); F(n+1)=n*f0; end stem(F,abs,(C)), grid, title(['Line Spectrum: Harmonics = ' num2str(Nmax)]); xlabel('Freq(Hz)'), ylabel('Cn'), shg disp('Hit return...'); pause %--- yest=a0*ones(1,length(T)); for n=1:Nmax yest=yest+a(n)*cos(2*n*pi*T/T0)+b(n)*sin(2*n*pi*T/T0);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT