• 大小: 20KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-15
  • 语言: Java
  • 标签: JavaOpencv  

资源简介

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个文件信息

评论

共有 条评论