how to get pixel coordinates in implay

6 vues (au cours des 30 derniers jours)
Juergen
Juergen le 19 Déc 2024
Commenté : Jayanti le 20 Déc 2024
Hello,
Is there a way to get the mouse onclick x,y pixel coordinates when playing a movie in implay.

Réponse acceptée

Jayanti
Jayanti le 19 Déc 2024
Modifié(e) : Jayanti le 19 Déc 2024
Hi Juergen,
Theimplayfunction in MATLAB does not provide direct access to pixel coordinates on click event.
Alternatively you can try achieving this through custom implementation by using “VideoReaderto read video frames and displaying them in a MATLAB figure where you can capture mouse events.
Please refer to the below code:
videoReader = VideoReader('file.mp4');
hFig = figure;
while hasFrame(videoReader)
frame = readFrame(videoReader);
imshow(frame, 'Parent', gca);
[x, y, button] = ginput(1);
if ~isempty(button)
fprintf('Clicked at X: %f, Y: %f\n', x, y);
end
pause(1/videoReader.FrameRate);
end
The video will be paused at each frame, where “ginput” function captures the x and y coordinates of a mouse click, which will be printed to the command window.
Please refer to the documentation link on “ginput” for your reference:
Hope this will be useful!
  2 commentaires
Juergen
Juergen le 19 Déc 2024
Hi Jayanti, thanks a lot.
Is there a way so that the movie runs and is only stopped if there is a mouse click on the image?
Jayanti
Jayanti le 20 Déc 2024
Hi Juergen,
In the above implementation, we extract each frame individually instead of playing the video. This allows us to capture mouse events. If you don't want to click on a frame, you can press the "Return" key. This will proceed to the next frame.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by