matlab練習程序(攝像頭視頻中截圖)


  在讀入攝像頭數據的時候,按下ctrl+x鍵,可以截取圖像,就是這樣一個功能。功能不多,但很有用。

main.m

clear all;
close all;
clc;
global m;  
obj=videoinput('winvideo',1,'YUY2_320x240');        
h1=preview(obj);                 %預覽視頻,同時獲取句柄  
h2=figure('KeyPressFcn',@keyPressFigure);                    %新建顯示圖像figure,同時獲取句柄

while ishandle(h1) && ishandle(h2)              %兩個句柄有一個關閉就結束程序
    frame=getsnapshot(obj);     %捕獲圖像
    frame=ycbcr2rgb(frame);     %轉成彩色,這個frame就可以按照自己意願處理了
    subplot(1,2,1);
    imshow(frame);  
    drawnow;
    subplot(1,2,2);
    imshow(m);          
end
delete(obj);                %刪除對象

KeyPressFigure.m

function keyPressFigure(src,event) 
    global m;
        % CTRL + x 
    if length(event.Modifier) == 1 & strcmp(event.Modifier{:}, 'control') & event.Key == 'x' 
       m=imcrop();
    end

end


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM