Matlab 中的实时网络摄像头处理

发布于 2024-11-05 11:49:19 字数 98 浏览 0 评论 0原文

谁能给我指出一些在 Matlab 中进行实时网络摄像头处理的示例?网上有一些关于如何从网络摄像头获取图片,然后处理该图片的教程/示例,但我正在研究对来自网络摄像头的视频源的实时操作。

Can anyone point me in the direction of some examples of live webcam processing in Matlab? There are some tutorials/examples online on how to acquire a picture from a webcam, and then process that picture, but I'm looking at real-time manipulation of the video feed from the webcam.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沫雨熙 2024-11-12 11:49:19

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

关于此视频:使用 USB 网络摄像头
读入数独谜题和图像
处理以从中提取数据。
然后,使用简单的方法解决这个难题
数值算法并叠加
原始视频源上的解决方案。

“SUDOKU”是以下公司的注册商标
NIKOLI有限公司(日本)

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

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

About this video: Use a USB webcam to
read in a Sudoku puzzle and image
processing to extract data from it.
Then, solve the puzzle using a simple
numerical algorithm and overlay the
solution on the original video feed.

"SUDOKU" is a registered trade mark by
NIKOLI Co., Ltd. (Japan)

[Edit - updated the link to the video]

灯下孤影 2024-11-12 11:49:19

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

The example Ashish gave does cover everything you need to know.

Here is a subset of this example with just the video stuff. Basically what you should do is a loop with a try catch. The loop gets frames from obj (the video object), processes and displays it by 'painting' straight on an imshow canvas.

The try-catch is there for when the user closes the figure window, causing an exception which triggers the catch clause - stopping the capture and releasing the camera (so other programs could use it)

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文