How to write frames into video after applying bounding box ?
6 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Image Analyst
on 28 Nov 2021
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 Comments
Image Analyst
on 28 Nov 2021
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!