我想用MATLAB在视频中的帧上插入一个圆圈。我希望在某些视频帧中出现指定情况时插入圆圈。这些特殊条件将在稍后出现,但我的问题如下:如何在视频的某些帧中叠加圆圈?
我到目前为止的代码如下:
xyloObj = VideoReader('shishe.mp4');
%%
nFrames = xyloObj.NumberOfFrames;
vidHeight = xyloObj.Height;
vidWidth = xyloObj.Width;
energy=zeros(xyloObj.NumberOfFrames,3);
% Preallocate the movie structure.
mov(1:nFrames) = ...
struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...
'colormap',[]);
% Read one frame at a time.
for k = 1 : nFrames
mov(k).cdata = read(xyloObj,k);
b2=rgb2hls_fst(mov(k).cdata);
r1=b2(:,:,1);
r2=b2(:,:,2);
r3=b2(:,:,3);
energy(k,1)=sum(sum(r1 .* r1))/ numel(r1);
energy(k,2)=sum(sum(r2 .* r2))/ numel(r2);
energy(k,3)=sum(sum(r3 .* r3))/ numel(r3);
%if(mycondition)
% (insert shape)
%end
end
答案 0 :(得分:0)
我找到了答案,并使用下面的代码进行操作
我在mov(k).cdata= insertShape( mov(k).cdata, 'circle', [320 240 200],'Color',{dcolor});
%%
clc
range=5;
for k = 1 : nFrames
meanenergy=energy(k,3);
if(k>range && k< nFrames-range)
meanenergy=mean( energy(k-5:k+5,3));
end
if(meanenergy >=ThresholdRed)
% disp('red');
dcolor='red';
elseif(meanenergy >= ThresholdYellow )
% disp('yellow');
dcolor='yellow';
else
% disp('green');
dcolor='green';
end
mov(k).cdata= insertShape( mov(k).cdata, 'circle', [320 240 200],'Color',{dcolor});
end
disp('end');
implay(mov)