plot with reversed y-axis in a normal y-axis
조회 수: 10 (최근 30일)
이전 댓글 표시
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?!
댓글 수: 0
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Biotech and Pharmaceutical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!