How to play video in matlab for computer vision?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ashokraj
am 17 Jul. 2024
Kommentiert: Image Analyst
am 20 Jul. 2024
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)
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 17 Jul. 2024
Do you really need to re-instantiate the video player inside the while loop? Try moving these lines before the while loop
% Instantiate the video player
vidPlayer = vision.DeployableVideoPlayer;
and remove them from inside the loop.
Which one of those lines in the loop actually does the update with the new frame image?
You might also try putting a "drawnow" command in variouis places and see if that helps with the flicker.
3 Kommentare
Image Analyst
am 20 Jul. 2024
You can call the Mathworks and ask about the Coder Toolbox. I haven't used it but I think it somehow lets you take your code and make it so it can be embedded in firmware or silicon on portable or detached, standalone devices.
If this Answer solves your original question, then could you please click the "Accept this answer" link to award the answerer with "reputation points" for their efforts in helping you? They'd appreciate it. Thanks in advance. 🙂 Note: you can only accept one answer (so pick the best one) but you can click the "Vote" icon for as many Answers as you want. Voting for an answer will also award reputation points.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!