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

10 ビュー (過去 30 日間)
Suzuki
Suzuki 2023 年 3 月 30 日
編集済み: Suzuki 2023 年 4 月 5 日
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?!

採用された回答

Jack
Jack 2023 年 3 月 30 日
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 件のコメント
Suzuki
Suzuki 2023 年 4 月 3 日
編集済み: Suzuki 2023 年 4 月 3 日
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 2023 年 4 月 5 日
編集済み: Suzuki 2023 年 4 月 5 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBiotech and Pharmaceutical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by