how can i correct this code to write a video

2 vues (au cours des 30 derniers jours)
bay rem
bay rem le 24 Jan 2016
Commenté : bay rem le 24 Jan 2016

I've this code and i dont know how to write a video with images result:

clear all;
close all;
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...
    'NumTrainingFrames', 300,'MinimumBackgroundRatio', 0.6);
videoReader = vision.VideoFileReader('video6.avi',...
for J=1:250
    frameRGB = step(videoReader); % read the next video frame
    foreground1 = step(foregroundDetector, frameRGB);
L = bwlabel(foreground);
s = regionprops(L, 'Area');
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);
      figure(J); imshow(result); title('Detected person');
      v = VideoWriter('video.avi');

can anyone please tell why the video result contains only one frame please

Réponse acceptée

Image Analyst
Image Analyst le 24 Jan 2016
What is "numperso"? Is it 1? That would explain it.
  3 commentaires
Image Analyst
Image Analyst le 24 Jan 2016
Since you open a new video for each frame and you write out the same number of frames as people, you will have a whole bunch of movies with only 1 or 2 frames. But like Walter pointed out, you're using the same name for each video so you're just overwriting the previous video at each frame and you end up with just one video, not lots of them. Not sure what you want to do so we're not sure how to recommend fixing it.
bay rem
bay rem le 24 Jan 2016
thank you soo much ,it's working now :)

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 24 Jan 2016
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 commentaire
bay rem
bay rem le 24 Jan 2016
THANK You soooo much , its working now :)

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by