how to get pixel coordinates in implay
6 views (last 30 days)
Show older comments
Hello,
Is there a way to get the mouse onclick x,y pixel coordinates when playing a movie in implay.
0 Comments
Accepted Answer
Jayanti
on 19 Dec 2024
Edited: Jayanti
on 19 Dec 2024
Hi Juergen,
The“implay”function in MATLAB does not provide direct access to pixel coordinates on click event.
Alternatively you can try achieving this through custom implementation by using “VideoReader”to 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
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.
More Answers (0)
See Also
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!