Y-Label upside down on on videoreader

7 views (last 30 days)
Hello!
So, I have a video I'm reading frame by frame. I need to acquire some data from it using ginput, so I need the axis to be right.
My code is:
mov = VideoReader('pendulo.mp4'); % estrutura com video
nFrames = mov.NumFrames; % numero de frames
framerate = mov.FrameRate; % numero de frames por segundo
dtframes=1/framerate; %tempo entre frames
i=1; t=0; tf=nFrames*dtframes; dt=10*dtframes;
if ~exist('dados.mat','file')
while (t <= tf)
mov.CurrentTime=t; frame=readFrame(mov); image(frame); drawnow
tv(i)=t; t=t+dt; title(strcat('Frame ', num2str(i)));
if i>1
hold on;
plot(x,y,'ro');
end
[x(i), y(i)]=ginput(1);
i=i+1;
end
I don't understand why the label is upside down... thanks!

Accepted Answer

Image Analyst
Image Analyst on 20 Jun 2021
It's not upside down. Since you first displayed the image, and then put hold on (so you could overlay graphics on top of it), the graphics from plot will use the image origin as the plot origin, instead of the lower left like plot() uses if there is not an image already in the axes with hold on. This means the origin for plot() is NOW in the upper left, as is usual/normal for images. If the x and y in your plot do not correspond to actual pixel (x,y) coordinates, but to some other coordinate system not based on pixels, then you will need to use rescale() to scale/flip/translate your plotting coordinates to match your image coordinates.
Attach dados.mat with the paperclip icon if you still have doubts, though I have no idea how you're using that mat file since you never seem to load it. And a zipped up 'pendulo.mp4' if it's less than 5 MB.
By the way, with recent versions of MATLAB you can use isfile() and isfolder(), so replace
if ~exist('dados.mat','file')
with
if ~isfile('dados.mat')

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 20 Jun 2021
The cause can be explained with data import and record them into MATLAB workspace. You may consider using flip() to correct the orientation then.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!