有人能指出我在Matlab中进行实时网络摄像头处理的一些例子吗?有一些关于如何从网络摄像头获取图片的在线教程/示例,然后处理该图片,但我正在考虑从网络摄像头实时处理视频源。
答案 0 :(得分:5)
http://www.mathworks.com/videos/solving-a-sudoku-puzzle-using-a-webcam-68773.html
关于此视频:使用USB网络摄像头 阅读数独谜题和图像 处理从中提取数据。 然后,使用简单的解决难题 数值算法和叠加 解决原始视频源。
“SUDOKU”是一个注册商标 NIKOLI Co.,Ltd。(日本)
[编辑 - 更新了视频链接]
答案 1 :(得分:1)
Ashish给出的例子涵盖了你需要知道的一切。
以下是此示例的一个子集,仅包含视频内容。基本上你应该做的是一个带有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