5vues (au cours des 30derniers jours)
Afficher commentaires plus anciens
Suzuki le 30 Mar 2023
-
-
Lien
Utiliser le lien direct vers cette question
https://fr.mathworks.com/matlabcentral/answers/1937959-plot-with-reversed-y-axis-in-a-normal-y-axis
Modifié(e): Suzuki le 5 Avr 2023
Réponse acceptée: Jack
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?!
0commentaires Afficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens
Afficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens
Connectez-vous pour commenter.
Connectez-vous pour répondre à cette question.
Réponse acceptée
Jack le 30 Mar 2023
⋮
Ouvrir dans MATLAB Online
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.
4commentaires Afficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
Afficher 2 commentaires plus anciensMasquer 2 commentaires plus anciens
Suzuki le 31 Mar 2023
Utiliser le lien direct vers ce commentaire
https://fr.mathworks.com/matlabcentral/answers/1937959-plot-with-reversed-y-axis-in-a-normal-y-axis#comment_2684524
Thanks.
I have tried that, but it still plot the eye pos using the video y-axis.
I tried yyaxis left and right but it slows down the video when I plot it togrther with the eye pos.
the eye pos are adjusted I belive, because if I plot the video and the eye pos seperately, the position is correct, it is only wrong when they are together because the video y-axis is reversed. I can only reverse it if I flip the image but then the image is not in the right shape.
Jack le 31 Mar 2023
Utiliser le lien direct vers ce commentaire
https://fr.mathworks.com/matlabcentral/answers/1937959-plot-with-reversed-y-axis-in-a-normal-y-axis#comment_2685499
Ouvrir dans MATLAB Online
If the yyaxis command is slowing down the video playback when you plot it together with the eye position, you can try a different approach to adjust the y-axis limits of the video plot to match the reversed y-axis of the eye position plot. Here's an example code snippet that might help:
% create a sample video and eye position data
video = rand(100, 100, 50);
eye_pos = rand(50, 2);
% plot the video and eye position separately to adjust the y-axis limits
subplot(2, 1, 1);
imshow(video(:,:,1));
xlim([1 size(video, 2)]);
ylim([1 size(video, 1)]);
subplot(2, 1, 2);
plot(eye_pos(:,1), size(video, 1) - eye_pos(:,2) + 1, 'b'); % adjust the y-coordinates
xlim([1 size(video, 2)]);
ylim([1 size(video, 1)]);
% plot the video and eye position together
figure;
imshow(video(:,:,1));
hold on;
plot(eye_pos(:,1), size(video, 1) - eye_pos(:,2) + 1, 'b'); % adjust the y-coordinates
hold off;
xlim([1 size(video, 2)]);
ylim([1 size(video, 1)]);
In this code, we plot the video and eye position separately to adjust the y-axis limits of both plots to match the reversed y-axis of the eye position data. Then we plot them together using imshow for the video and plot for the eye position, with the hold on and hold off commands to combine the plots. We also adjust the y-coordinates of the eye position data by subtracting them from the height of the video and adding 1 to shift them to the correct y-axis position.
I hope this helps! Let me know if you have any further questions.
Suzuki le 3 Avr 2023
Utiliser le lien direct vers ce commentaire
https://fr.mathworks.com/matlabcentral/answers/1937959-plot-with-reversed-y-axis-in-a-normal-y-axis#comment_2687704
Modifié(e): Suzuki le 3 Avr 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 le 5 Avr 2023
Utiliser le lien direct vers ce commentaire
https://fr.mathworks.com/matlabcentral/answers/1937959-plot-with-reversed-y-axis-in-a-normal-y-axis#comment_2690804
Modifié(e): Suzuki le 5 Avr 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.
Connectez-vous pour commenter.
Plus de réponses (0)
Connectez-vous pour répondre à cette question.
Voir également
Catégories
Image Processing and Computer VisionImage Processing ToolboxImage Filtering and EnhancementImage Arithmetic
En savoir plus sur Image Arithmetic dans Help Center et File Exchange
Tags
- reverse y-axis
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
Une erreur s'est produite
Impossible de terminer l’action en raison de modifications de la page. Rechargez la page pour voir sa mise à jour.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asie-Pacifique
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contactez votre bureau local