plot with reversed y-axis in a normal y-axis

9 views (last 30 days)
I have a video plotted (or played frame by fame) and I want to plot a shape representing the corresponding eye position.
The video has its y-axis reversed (can't control it) (0 up). The eye position is with coordinates in which the y-axis is normal (0 at bottom).
I need to plot this eye position somehow with reversed y-axis on the video.
I'm using insertShape but I can't change the position of the shape to be plotted in a reversed y-axis on the video. I tried flip, axis handel, and many things, nothing is working.
Any suggestion please?!

Accepted Answer

Jack
Jack on 30 Mar 2023
You can use the image function in MATLAB to display the video frames and then use insertShape to plot the eye position on top of the frame. To reverse the y-axis, you can set the YDir property of the axes object to 'reverse'. Here's some sample code to get you started:
% Load the video file
v = VideoReader('my_video.mp4');
% Create a figure and axes to display the frames
fig = figure;
ax = axes('Parent', fig);
% Set the y-axis direction to 'reverse'
set(ax, 'YDir', 'reverse');
% Loop through the frames and display them
while hasFrame(v)
frame = readFrame(v);
image(ax, frame);
% Get the eye position for the current frame
eye_pos = [x, y, width, height]; % Replace with your own code
% Plot the eye position on top of the frame
insertShape(ax, 'Rectangle', eye_pos, 'Color', 'red');
% Update the figure
drawnow;
end
In this code, x, y, width, and height are the coordinates of the eye position in a normal y-axis coordinate system. You may need to adjust these values to match the dimensions of your video frames. The insertShape function plots a red rectangle at the specified eye position, and the drawnow function updates the figure to display the current frame with the eye position.
  4 Comments
Suzuki
Suzuki on 3 Apr 2023
Edited: Suzuki on 3 Apr 2023
Thanks.
When I tried that it plots frame 1 then the eye trace on what seems to be a different figure (because the background is white, not the video frame 1 (for ex)), but if i remove the hold off it' ok. However, the eye traces are not in the correct position. Furthermore,it plots the video images in black and white, don't know why.
And I also tried your example, but the eye traces are also plotted in the lower corner of the video, I guess this is not the right position.
Suzuki
Suzuki on 5 Apr 2023
Edited: Suzuki on 5 Apr 2023
Hey Jack,
I was doing something incorrect, but I've corrected it.
Your codes worked ,it flipped the eye pos, but no need for the +1.
thank alot.

Sign in to comment.

More Answers (0)

Categories

Find more on Biotech and Pharmaceutical 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!