java使用jframe在mat中显示图像(OpenCV 3.00)
如何在JFrame
中显示Mat图像SetIcon()
不接受mat参数。在显示之前,应在OpenCV 3.00
中使用图像。但是OpenCV只能打开mat图像。有什么方法可以转换图像吗
public void displayImage()
{
Mat image = Imgcodecs.imread(getClass().getResource("lena.png").getPath());
JFrame frame=new JFrame();
frame.setLayout(new FlowLayout());
JLabel lbl=new JLabel();
lbl.setIcon(image);
frame.add(lbl);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
我确实找到了转换它的代码,但是它有highgui
,这已经不在OpenCV 3.00中了
MatOfByte byteMat = new MatOfByte();
Highgui.imencode(".bmp", mat, byteMat);
return new Image(new ByteArrayInputStream(byteMat.toArray()));
# 1 楼答案
将垫子转换为BuffereImage,然后在面板、画布或类似区域上绘制: