在读入摄像头数据的时候,按下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

相关文章:

  • 2021-05-26
  • 2022-12-23
  • 2022-02-01
  • 2021-11-30
  • 2021-08-07
  • 2021-05-20
  • 2021-09-09
猜你喜欢
  • 2021-05-31
  • 2022-01-27
  • 2021-12-16
  • 2022-12-23
  • 2021-08-03
  • 2021-10-19
  • 2021-10-13
相关资源
相似解决方案