ROI in video using the first frame

14 views (last 30 days)
I would like to specify the box on the first frame of a video and then have all subsequent frames use that same box location.
I have a for loop here but unsure where should add this part in. Thank you!
for frame = 1 : numberOfFrames
% Extract the frame from the movie structure.
thisFrame = read(videoObject, frame);
thisFrame = thisFrame(557:702,70:216, :, :);
% Display it
hImage = subplot(1, 2, 1);
axis image;
ongoing = frame/framerate;
total = numberOfFrames/framerate;
caption = sprintf('Time %.3f of %.3f sec.', ongoing, total);
title(caption, 'FontSize', 20);
drawnow; % Force it to refresh the window.
Shu-An Hsieh
Shu-An Hsieh on 3 Oct 2022
I am trying to crop a circle on my video. The ROI will be based on the user.

Sign in to comment.

Accepted Answer

Kevin Holly
Kevin Holly on 3 Oct 2022
Edited: Kevin Holly on 3 Oct 2022
Read video and have user define Circle ROI:
v = VideoReader('xylophone.mp4');
frame = readFrame(v);
c = drawcircle;
After Circle ROI is define, you could have a pushbutton callback that creates a mask and plays video:
mask = createMask(c);
while hasFrame(v)
frame = readFrame(v);
Shu-An Hsieh
Shu-An Hsieh on 4 Oct 2022
Actually, I am thinking to the get the area between two points, so like you drag a line between two points and the area above and between those two is the area I wanted. Thank you!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by