How to play video in matlab for computer vision?

14 次查看(过去 30 天)
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)

回答(1 个)

Image Analyst
Image Analyst 2024-7-17,17:02
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 个评论
Ashokraj
Ashokraj 2024-7-20,14:05
how can I know what is the processing power required to implement this? whether do I need a controller or micro processor or fpga how can I know?
how to implement algorithms in microcontroller?
Image Analyst
Image Analyst 2024-7-20,16:16
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.

请先登录,再进行评论。

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by