2011-05-07 118 views
2

任何人都可以指出我的一些在Matlab实时摄像头处理的例子吗?网上有一些关于如何从网络摄像头获取图片的教程/示例,然后处理该图片,但我正在寻找从网络摄像头实时处理视频源的操作。在Matlab中实时摄像头处理

回答

5

http://www.mathworks.com/videos/solving-a-sudoku-puzzle-using-a-webcam-68773.html

关于该视频:使用USB网络摄像头 的数独题和图像处理 读从中提取数据。 然后,使用简单的 数值算法解决难题,并在原始视频供稿上覆盖 解决方案。

“数独”是 NIKOLI有限公司的注册商标(日本)

[编辑 - 更新链接到视频]

+0

这很有帮助。谢谢。 – 2011-05-11 21:21:22

+0

多数民众赞成超级有用! – twerdster 2011-06-11 11:19:45

+0

网站已关闭?备用链接? – aaronsnoswell 2012-10-29 13:35:11

1

阿希什给不面面俱到的例子你得知道。

这是这个例子的一个子集,只是视频的东西。基本上你应该做的是一个带有try catch的循环。循环从obj(视频对象)获取帧,通过直接在imshow画布上“绘画”来处理和显示它。

在try-catch有当用户关闭图窗口,从而导致其触发的catch子句的例外 - 停止捕获和释放相机(所以其他程序可以使用它)

function sudokuvideo_fn() 
% Reset everything, and start capturing 
imaqreset 
% The format need to fit to your camera. The easiest way to check this is 
% to check out the Image Aquisition app 
obj = videoinput('winvideo',1,'MJPG_640x480'); 

try 
    %Initialize various parameters, and load in the template data 
    set(obj,'framesperTrigger',10,'TriggerRepeat',Inf); 
    start(obj); 

    % h is a handle to the canvas 
    h = imshow(zeros(480,640)); 
    hold on; 

    figure(1); 

    while islogging(obj);    
     colorImage = getdata(obj,1); 
     %Icam = imread('sample.bmp'); %<--- For debugging 

     % This line depends on the format you're using (YUV/RGB) 
     %Icam = IcamColor(:,:,1); 
     Icam = rgb2gray(colorImage);  
     flushdata(obj); 

     bwthresh = 1.2; 
     %% Processing comes here - Do whatever you wish 
%   %Block processed threshhold 
%   makebw2 = @(I) im2bw(I.data,median(double(I.data(:)))/bwthresh/255); 
%   IBW = ~blockproc(I0,[blksize blksize],makebw2);  
     IBW = im2bw(Icam, bwthresh/255); 

     % Noise reduction and border elimination 
     I = IBW; 
%   IBW = imclose(IBW,[1 1; 1 1]); 
%   I = IBW; 
     I = bwareaopen(I, blobthresh); 
%   I = imclearborder(I); 

     %% This is what paints on the canvas 
     set(h,'Cdata',I); 
     drawnow; 
    end 

catch err 
    % This attempts to take care of things when the figure is closed 
    stop(obj); 
    imaqreset 
    disp('Cleaned up') 
    rethrow(err); 
end