how can i correct this code to write a video
Mostrar comentarios más antiguos
I've this code and i dont know how to write a video with images result:
clear all;
close all;
clc;
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
'NumTrainingFrames', 300,'MinimumBackgroundRatio', 0.6);
videoReader = vision.VideoFileReader('video6.avi',...
'VideoOutputDataType','uint8');
JJ=0;
j=0;
k=0;
m=0;
J=0;
for J=1:250
J=J+1
frameRGB = step(videoReader); % read the next video frame
foreground1 = step(foregroundDetector, frameRGB);
L = bwlabel(foreground);
s = regionprops(L, 'Area');
%s(1)
area_values = [s.Area];
idx3 = find((1700 <= area_values) & (area_values <= 1900000));
ForF = ismember(L, idx3);
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 1700,'MaximumCount',2);
bbox = step(blobAnalysis, ForF);
numperso = size(bbox,1);
%if J>=90 && J<99
if numperso>0
for i=1: numperso
blobVariance(i) = var(double(bbox(i,:)));
[minimumE2,IE2] = max(blobVariance);
result = insertShape(frame, 'Rectangle', bbox(IE2,:), 'Color', 'red');
result = insertText(result, [10 10], numperso, 'BoxOpacity', 1, ...
'FontSize', 14);
blobVariance(i)=[];
figure(J); imshow(result); title('Detected person');
v = VideoWriter('video.avi');
open(v);
writeVideo(v,figure(J))
end
end
close(v);
end
can anyone please tell why the video result contains only one frame please
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 24 de En. de 2016
0 votos
Do not create and open the videowriter object inside the loop: when you do that, you are overwriting the file over and over again.
1 comentario
bay rem
el 24 de En. de 2016
Categorías
Más información sobre Video Formats and Interfaces en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!