开发者

Realtime webcam processing in Matlab

开发者 https://www.devze.com 2023-03-03 08:57 出处:网络
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 p

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.


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]


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号