激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - Java教程 - 詳解使用JavaCV/OpenCV抓取并存儲攝像頭圖像

詳解使用JavaCV/OpenCV抓取并存儲攝像頭圖像

2020-09-08 10:53ljsspace Java教程

本篇文章主要介紹了使用JavaCV/OpenCV抓取并存儲攝像頭圖像,實例分析了使用JavaCV/OpenCV抓取并存儲攝像頭圖像的技巧,非常具有實用價值,需要的朋友可以參考下

本程序通過JFrame實時顯示本機攝像頭圖像,并將圖像存儲到一個緩沖區(qū),當(dāng)用戶用鼠標(biāo)點擊JFrame中任何區(qū)域時,顯示抓取圖像的簡單動畫,同時保存緩沖區(qū)的圖像到磁盤文件中。點擊JFrame關(guān)閉按鈕可以退出程序。

實現(xiàn):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
 
import javax.imageio.ImageIO;
import javax.swing.Timer;
 
import com.googlecode.javacv.CanvasFrame;
import com.googlecode.javacv.OpenCVFrameGrabber;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import static com.googlecode.javacv.cpp.opencv_core.cvReleaseImage;
 
/**
 *
 * Use JavaCV/OpenCV to capture camera images
 *
 * There are two functions in this demo:
 * 1) show real-time camera images
 * 2) capture camera images by mouse-clicking anywhere in the JFrame,
 * the jpg file is saved in a hard-coded path.
 *
 * @author ljs
 * 2011-08-19
 *
 */
public class CameraCapture {
  public static String savedImageFile = "c:\\tmp\\my.jpg";
   
  //timer for image capture animation
  static class TimerAction implements ActionListener {
    private Graphics2D g;
    private CanvasFrame canvasFrame;
    private int width,height;
     
    private int delta=10;
    private int count = 0;
     
    private Timer timer;
    public void setTimer(Timer timer){
      this.timer = timer;
    }
      
    public TimerAction(CanvasFrame canvasFrame){
      this.g = (Graphics2D)canvasFrame.getCanvas().getGraphics(); 
      this.canvasFrame = canvasFrame;
      this.width = canvasFrame.getCanvas().getWidth();
      this.height = canvasFrame.getCanvas().getHeight();
    }
    public void actionPerformed(ActionEvent e) {
      int offset = delta*count;
      if(width-offset>=offset && height-offset >= offset) {    
        g.drawRect(offset, offset, width-2*offset, height-2*offset);
        canvasFrame.repaint();
        count++;
      }else{
        //when animation is done, reset count and stop timer.
        timer.stop();
        count = 0;
      }      
    }
  }
 
  public static void main(String[] args) throws Exception {
    //open camera source
    OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
    grabber.start();
     
    //create a frame for real-time image display
    CanvasFrame canvasFrame = new CanvasFrame("Camera");
    IplImage image = grabber.grab();
    int width = image.width();
    int height = image.height();
    canvasFrame.setCanvasSize(width, height);
     
    //onscreen buffer for image capture
    final BufferedImage bImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D bGraphics = bImage.createGraphics();   
     
    //animation timer
    TimerAction timerAction = new TimerAction(canvasFrame);
    final Timer timer=new Timer(10, timerAction);
    timerAction.setTimer(timer);
      
    //click the frame to capture an image
    canvasFrame.getCanvas().addMouseListener(new MouseAdapter(){
      public void mouseClicked(MouseEvent e){   
        timer.start(); //start animation
        try {
          ImageIO.write(bImage, "jpg", new File(savedImageFile));
        } catch (IOException e1) {
          e1.printStackTrace();
        }          
      }        
    });
     
    //real-time image display
    while(canvasFrame.isVisible() && (image=grabber.grab()) != null){
      if(!timer.isRunning()) { //when animation is on, pause real-time display
        canvasFrame.showImage(image);  
        //draw the onscreen image simutaneously
        bGraphics.drawImage(image.getBufferedImage(),null,0,0); 
      }
    }
     
    //release resources
    cvReleaseImage(image);  
    grabber.stop();
    canvasFrame.dispose();
  }
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:http://blog.csdn.net/ljsspace/article/details/6702178

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 美女毛片在线观看 | 免费激情网站 | 国产精品9191 | 久久久www成人免费毛片 | 中文字幕在线看第二 | 色婷婷综合久色aⅴ | 欧美高清在线精品一区二区不卡 | 成人毛片视频免费看 | 久久99精品久久久久久秒播蜜臀 | 久久精品日产高清版的功能介绍 | 欧美日韩在线免费观看 | 黄色一级视频 | 成人免费观看在线 | 一边吃奶一边插下面 | 91丝袜| h视频免费观看 | 精品国产一区二区三区四区在线 | 27xxoo无遮挡动态视频 | 欧美成人二区 | 欧美国产永久免费看片 | 精品国产91久久久久久久妲己 | 九九午夜| 宅男噜噜噜66国产免费观看 | 老女人碰碰在线碰碰视频 | 久久99国产精品久久99 | 黄色免费入口 | 欧美视频一区二区三区在线观看 | 国产精品99久久久久久董美香 | 欧美成年私人网站 | 黄网站免费在线看 | 娇妻被各种姿势c到高潮小说 | 538任你躁在线精品视频网站 | xxnxx中国18 | 久久精品成人影院 | 国产精品午夜在线 | 日本高清黄色片 | 黄色美女网站免费看 | 成人三级视频网站 | 中文字幕 亚洲一区 | 国产91九色 | 成人男男视频拍拍拍在线观看 |