資源簡介
Java Opencv系列:(配套代碼下載)4.3讀取攝像頭并顯示

代碼片段和文件信息
package?imageIO;
import?java.awt.EventQueue;
import?javax.swing.ImageIcon;
import?javax.swing.Jframe;
import?javax.swing.JLabel;
import?org.opencv.core.Core;
import?org.opencv.core.Mat;
import?org.opencv.videoio.VideoCapture;
import?tool.mat2BufferedImage;
import?javax.swing.JButton;
import?java.awt.event.MouseAdapter;
import?java.awt.event.MouseEvent;
public?class?CameraBasic?{
static{System.loadLibrary(Core.NATIVE_LIBRARY_NAME);}
private?Jframe?frame;
static?JLabel?label;
static?int?flag=0;
/**
?*?Launch?the?application.
?*/
public?static?void?main(String[]?args)?{
EventQueue.invokeLater(new?Runnable()?{
public?void?run()?{
try?{
CameraBasic?window?=?new?CameraBasic();
window.frame.setVisible(true);
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
});
//我們的操作
VideoCapture?camera=new?VideoCapture();
camera.open(0);
if(!camera.isOpened()){
System.out.println(“Camera?Error“);
}
else{
Mat?frame=new?Mat();
while(flag==0){
camera.read(frame);
label.setIcon(new?ImageIcon(mat2BufferedImage.matToBufferedImage(frame)));
try?{
Thread.sleep(100);
}?catch?(InterruptedException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
}
}
/**
?*?Create?the?application.
?*/
public?CameraBasic()?{
initialize();
}
/**
?*?Initialize?the?contents?of?the?frame.?
?*/
private?void?initialize(){
frame?=?new?Jframe();
frame.setBounds(100?100?800?450);
frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JButton?btnNewButton?=?new?JButton(“\u62CD\u7167“);
btnNewButton.addMouseListener(new?MouseAdapter()?{
@Override
public?void?mouseClicked(MouseEvent?arg0)?{
flag=1;
}
});
btnNewButton.setBounds(33?13?113?27);
frame.getContentPane().add(btnNewButton);
label?=?new?JLabel(““);
label.setBounds(0?0?800?450);
frame.getContentPane().add(label);
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\
?????文件?????????378??2017-03-24?13:26??4.3讀取攝像頭并顯示\testOpencv\.classpath
?????文件?????????386??2017-03-24?13:14??4.3讀取攝像頭并顯示\testOpencv\.project
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\.settings\
?????文件?????????598??2017-03-24?13:14??4.3讀取攝像頭并顯示\testOpencv\.settings\org.eclipse.jdt.core.prefs
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\bin\
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\bin\imageIO\
?????文件?????????829??2017-03-28?20:34??4.3讀取攝像頭并顯示\testOpencv\bin\imageIO\CameraBasic$1.class
?????文件?????????659??2017-03-28?20:34??4.3讀取攝像頭并顯示\testOpencv\bin\imageIO\CameraBasic$2.class
?????文件????????2777??2017-03-28?20:34??4.3讀取攝像頭并顯示\testOpencv\bin\imageIO\CameraBasic.class
?????文件????????1197??2017-03-28?20:32??4.3讀取攝像頭并顯示\testOpencv\bin\imageIO\ReadAndWriteImage.class
?????文件?????????817??2017-03-28?20:32??4.3讀取攝像頭并顯示\testOpencv\bin\imageIO\ShowImage$1.class
?????文件????????1949??2017-03-28?20:32??4.3讀取攝像頭并顯示\testOpencv\bin\imageIO\ShowImage.class
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\bin\matAction\
?????文件????????1862??2017-03-28?20:32??4.3讀取攝像頭并顯示\testOpencv\bin\matAction\LinearAlgebraBasic.class
?????文件????????1761??2017-03-28?20:32??4.3讀取攝像頭并顯示\testOpencv\bin\matAction\LinearAlgebraMiddle.class
?????文件????????1662??2017-03-28?20:32??4.3讀取攝像頭并顯示\testOpencv\bin\matAction\NewMat.class
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\bin\tool\
?????文件????????1280??2017-03-28?20:32??4.3讀取攝像頭并顯示\testOpencv\bin\tool\mat2BufferedImage.class
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\src\
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\src\imageIO\
?????文件????????2090??2017-03-28?20:34??4.3讀取攝像頭并顯示\testOpencv\src\imageIO\CameraBasic.java
?????文件?????????606??2017-03-27?17:14??4.3讀取攝像頭并顯示\testOpencv\src\imageIO\ReadAndWriteImage.java
?????文件????????1391??2017-03-28?19:32??4.3讀取攝像頭并顯示\testOpencv\src\imageIO\ShowImage.java
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\src\matAction\
?????文件????????1163??2017-03-24?20:58??4.3讀取攝像頭并顯示\testOpencv\src\matAction\LinearAlgebraBasic.java
?????文件?????????951??2017-03-27?16:16??4.3讀取攝像頭并顯示\testOpencv\src\matAction\LinearAlgebraMiddle.java
?????文件?????????792??2017-03-24?20:05??4.3讀取攝像頭并顯示\testOpencv\src\matAction\NewMat.java
?????目錄???????????0??2017-03-29?16:12??4.3讀取攝像頭并顯示\testOpencv\src\tool\
?????文件?????????874??2017-03-28?19:32??4.3讀取攝像頭并顯示\testOpencv\src\tool\mat2BufferedImage.java
............此處省略0個文件信息
- 上一篇:XDA簽名工具
- 下一篇:java實現漢諾塔小游戲
評論
共有 條評論