how to get pixel coordinates in implay

6 views (last 30 days)
Hello,
Is there a way to get the mouse onclick x,y pixel coordinates when playing a movie in implay.

Accepted Answer

Jayanti
Jayanti on 19 Dec 2024
Edited: Jayanti on 19 Dec 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 Comments
Juergen
Juergen on 19 Dec 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 on 20 Dec 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Animation 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!