2012-04-15 76 views
0

我有拍攝實時視頻的代碼,我有代碼在圖像上畫兩條線,所以我想將兩個代碼組合在一起,並且當一個對象出現在線上時,顏色會發生變化。我該怎麼做呢?MATLAB的實時視頻

以下是兩個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; 

回答

0

查找Simulink的演示viptrackpeople。您可以嘗試將視頻源塊從「多媒體文件」更改爲阻止「來自視頻設備的圖像」,然後添加一個包含MATLAB處理代碼的塊。我沒有視頻設備,所以我無法驗證此方法。

+0

謝謝,但我不想使用Simulink你有任何其他的解決方案,請 – 2012-04-16 16:39:56