本篇博客介绍如何在Java中使用Opencv实现对图片的读取和显示。
首先是显示部分:
import java.awt.Component;
import java.awt.EventQueue;
import java.awt.image.BufferedImage;
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.imgcodecs.Imgcodecs;
public class ShowImage {
private JFrame frame;
/**
* Create the application.
*/
public ShowImage(Mat mat) {
initialize(mat);
}
public JFrame getFrame() {
return frame;
}
/**
* Initialize the contents of the frame.
*/
private void initialize(Mat mat) {
frame = new JFrame();
frame.setBounds(20, 100, mat.width()+100, mat.height()+80);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLay