how to reduce blob analysis rate in video so that object counting can happen every 3 seconds
I would like to do object counting but my code is checking for region of intereste every 1/30 second due to 30 frames per second because of this everytime it is detecting the object, any way i can solve this problem?
clc;
%% Setup of video
vidReader=vision.VideoFileReader(‘hvsstop2.mp4’);
vidReader.VideoOutputDataType=’double’;
mywriter=VideoWriter(‘mymovie.mp4’);
open(mywriter);
%% structural element
diskelem=strel(‘disk’,2);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,1500,’MaximumBlobArea’,4000);
vidPlayer = vision.DeployableVideoPlayer;
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.615;
channel1Max = 0.962;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 0.058;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.723;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
%ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
%iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’cardboard’,TextBoxOpacity=0.9,FontSize=18);
iannotate_vid = insertObjectAnnotation(vidframe,"rectangle",…
bboxOut,’versatilis’,TextBoxOpacity=0.9,FontSize=30);
%paly in video player
vidPlayer(iannotate_vid);
writeVideo(mywriter,iannotate_vid);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
close(mywriter)
%release(ishape)I would like to do object counting but my code is checking for region of intereste every 1/30 second due to 30 frames per second because of this everytime it is detecting the object, any way i can solve this problem?
clc;
%% Setup of video
vidReader=vision.VideoFileReader(‘hvsstop2.mp4’);
vidReader.VideoOutputDataType=’double’;
mywriter=VideoWriter(‘mymovie.mp4’);
open(mywriter);
%% structural element
diskelem=strel(‘disk’,2);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,1500,’MaximumBlobArea’,4000);
vidPlayer = vision.DeployableVideoPlayer;
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.615;
channel1Max = 0.962;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 0.058;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.723;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
%ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
%iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’cardboard’,TextBoxOpacity=0.9,FontSize=18);
iannotate_vid = insertObjectAnnotation(vidframe,"rectangle",…
bboxOut,’versatilis’,TextBoxOpacity=0.9,FontSize=30);
%paly in video player
vidPlayer(iannotate_vid);
writeVideo(mywriter,iannotate_vid);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
close(mywriter)
%release(ishape) I would like to do object counting but my code is checking for region of intereste every 1/30 second due to 30 frames per second because of this everytime it is detecting the object, any way i can solve this problem?
clc;
%% Setup of video
vidReader=vision.VideoFileReader(‘hvsstop2.mp4’);
vidReader.VideoOutputDataType=’double’;
mywriter=VideoWriter(‘mymovie.mp4’);
open(mywriter);
%% structural element
diskelem=strel(‘disk’,2);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,1500,’MaximumBlobArea’,4000);
vidPlayer = vision.DeployableVideoPlayer;
while ~isDone(vidReader)
%read frame
vidframe=step(vidReader);
%rgb to hsv color space
I=rgb2hsv(vidframe);
%htextins=insertText(I,’position’,[20,20],’Color’,[255 255 0],’Fontsize’,30);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.615;
channel1Max = 0.962;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.000;
channel2Max = 0.058;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.723;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & …
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & …
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
%using morphological operations
ibwopen=imopen(BW,diskelem);
%extract the blobs from the frame
[areaOut,centroidOut, bboxOut]=step(hblob,ibwopen);
%draw a box around detected objects
%ishape=insertShape(vidframe,’Rectangle’,bboxOut,’ShapeColor’,’black’);
%iannotate = insertObjectAnnotation(vidframe,"rectangle",bboxOut,’cardboard’,TextBoxOpacity=0.9,FontSize=18);
iannotate_vid = insertObjectAnnotation(vidframe,"rectangle",…
bboxOut,’versatilis’,TextBoxOpacity=0.9,FontSize=30);
%paly in video player
vidPlayer(iannotate_vid);
writeVideo(mywriter,iannotate_vid);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
close(mywriter)
%release(ishape) computer vision, blob MATLAB Answers — New Questions