ROI in video using the first frame

12 次查看(过去 30 天)
Hi,
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);
image(thisFrame);
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.
  2 个评论
Kevin Holly
Kevin Holly 2022-10-3
Are you trying to crop a video to a rectangular region of interest (ROI)? Is the ROI defined by the user or based on the image?
Shu-An Hsieh
Shu-An Hsieh 2022-10-3
I am trying to crop a circle on my video. The ROI will be based on the user.

请先登录,再进行评论。

采纳的回答

Kevin Holly
Kevin Holly 2022-10-3
编辑:Kevin Holly 2022-10-3
Read video and have user define Circle ROI:
v = VideoReader('xylophone.mp4');
frame = readFrame(v);
imshow(frame)
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);
imshow(uint8(mask).*frame)
end
  22 个评论
Shu-An Hsieh
Shu-An Hsieh 2022-10-4
Thank you Kevin! I am wondering if it is possible the get several ranges and substact a base number out of it. Also, I am wondering if I can further save an additional figure of the right figure when the code ends.
Shu-An Hsieh
Shu-An Hsieh 2022-10-4
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!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Point Cloud Processing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by