How to write frames into video after applying bounding box ?
이전 댓글 표시
I have a video file from where I need to track an object in each frame. I have successfully done that using (rectangle('Position',[st.BoundingBox(1),st.BoundingBo). I have total 300 frames from that video and I need to write the images containing bounding box within the for loop.
for k=1: nframes
. . .. . .. .. .. . .. . .. .. . . .. .. . .
obj=bwareafilt(~dilated1, 1, 'largest');
figure(1);
imshow(I);
hold on
st = regionprops(obj, 'BoundingBox' );
BB = st(1).BoundingBox;
K=rectangle('Position',[st.BoundingBox(1),st.BoundingBox(2),st.BoundingBox(3),st.BoundingBox(4)],...
'EdgeColor','r','LineWidth',2 );
end
답변 (1개)
Image Analyst
2021년 11월 28일
Just burn them in. Like if you want it white
row1 = ceil(BB(2));
row2 = row1 + BB(4) - 1;
col1 = ceil(BB(1));
col2 = col1 + BB(3) - 1;
obj(row1:row2, col1) = 255;
obj(row1:row2, col2) = 255;
obj(row1, col1:col2) = 255;
obj(row2, col1:col2) = 255;
% Write this frame out to a new video file on disk.
writeVideo(videoWriterObject, obj);
See attached demos if you need more help in using writeVideo().
댓글 수: 2
Bipasha Kundu
2021년 11월 28일
Image Analyst
2021년 11월 28일
Correct. And the reason is that your code above totally ignores my suggestion. Why aren't you assigning the rows and columns to obj, and using writeVideo() like I suggested?
You can save the image to a frame movie structure instead of saving just the bare image alone, if you want. That's how I did it in the attached demo where I built a movie from individual saved image files.
카테고리
도움말 센터 및 File Exchange에서 Audio and Video Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!