我有用于拍摄实时视频的代码,并且我有在图像上绘制两条线的代码,所以我想将这两个代码组合在一起,当一个对象出现在线上时,颜色会发生变化。我该怎么做呢?
下面是两个 MATLAB 程序。
拍摄现场视频的代码:
clear;
dev_info = imaqhwinfo('winvideo',1);
celldisp(dev_info.SupportedFormats);
vid1 = videoinput('winvideo',1);
%out = imaqhwinfo(vid)
%This is for triggering:
num_frames=5;
triggerconfig(vid1, 'Manual')
set(vid1,'FramesPerTrigger',num_frames)
start(vid1);
trigger(vid1)
frame = getsnapshot(vid1);
image(frame);
%Here it will acquire five frames.
%Now move the data acquired to the workspace.
[data1 time1] = getdata(vid1,num_frames);
kk=length(time1);
elapsed_time = time1(kk) - time1(1);
%frame = getsnapshot(vid1); %This is to get a single frame.
%imaqmontage(data1)
%cleaning
delete(vid1);
clear vid1;
aviobj = avifile('example.avi')
for i=1:kk
F=data1(:,:,:,i);
aviobj = addframe(aviobj,F);
end
aviobj = close(aviobj);
%Then we can see the whole video clip.
mov = aviread('example.avi');
movie(mov)
%................
%Also, we can directly play the video from the video file.
mplay('example.avi');
在图像上绘制两条线的代码:
im = imread('image.jpg');
imshow(im);
hold on;
line([27,1523],[1753,1753]);
line([7,1531],[1395,1395]);
hold off;