How to play video in matlab for computer vision?
I am trying to do object recognition using blob analysis. when i did write the code the video is flickering every second, is it possible to have a video player running without flickering? I have attached my code below. please recommend me any changes
%% Setup of video
vidReader=vision.VideoFileReader(‘vidf.mp4’);
vidReader.VideoOutputDataType=’double’;
%% structural element
diskelem=strel(‘disk’,22);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,200,’MaximumBlobArea’,4000);
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.091;
channel1Max = 0.234;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.309;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
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,’banana’,TextBoxOpacity=0.9,FontSize=18);
%paly in video player
vidPlayer = vision.DeployableVideoPlayer;
%step(vidPlayer,ishape);
step(vidPlayer,iannotate);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
%release(ishape)I am trying to do object recognition using blob analysis. when i did write the code the video is flickering every second, is it possible to have a video player running without flickering? I have attached my code below. please recommend me any changes
%% Setup of video
vidReader=vision.VideoFileReader(‘vidf.mp4’);
vidReader.VideoOutputDataType=’double’;
%% structural element
diskelem=strel(‘disk’,22);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,200,’MaximumBlobArea’,4000);
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.091;
channel1Max = 0.234;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.309;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
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,’banana’,TextBoxOpacity=0.9,FontSize=18);
%paly in video player
vidPlayer = vision.DeployableVideoPlayer;
%step(vidPlayer,ishape);
step(vidPlayer,iannotate);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
%release(ishape) I am trying to do object recognition using blob analysis. when i did write the code the video is flickering every second, is it possible to have a video player running without flickering? I have attached my code below. please recommend me any changes
%% Setup of video
vidReader=vision.VideoFileReader(‘vidf.mp4’);
vidReader.VideoOutputDataType=’double’;
%% structural element
diskelem=strel(‘disk’,22);
hblob=vision.BlobAnalysis(‘MinimumBlobArea’,200,’MaximumBlobArea’,4000);
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.091;
channel1Max = 0.234;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.309;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
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,’banana’,TextBoxOpacity=0.9,FontSize=18);
%paly in video player
vidPlayer = vision.DeployableVideoPlayer;
%step(vidPlayer,ishape);
step(vidPlayer,iannotate);
end
%%release
release(vidReader)
release(hblob)
release(vidPlayer)
%release(ishape) computer vision, image processing MATLAB Answers — New Questions