我正在使用Java Opencv-2.4.4和swing GUI开发应用程序.问题是我无法找到任何解决方案,这显示了如何将处理后的图像(保存在Mat对象中)打印到java swing GUI的有效方法.就在这一刻,我正在使用这种笨拙的解决方案:
javax.swing.JLabel outputImage;
outputImage.setIcon(new javax.swing.ImageIcon("/home/username/Output.png"));
private void sliderStateChanged(javax.swing.event.ChangeEvent evt) {
.
.
Mat canny; // Here is saved what I want to plot
String filename = "/home/username/Output.png";
Highgui.imwrite(filename, canny); // write to disk
outputImage.setIcon(new ImageIcon(ImageIO.read(new File(filename)))); //update Icon
.
.
}
Run Code Online (Sandbox Code Playgroud)
当用户改变一些值,输入等等,在GUI我必须覆盖Output.png在磁盘上,并从磁盘上的新形象更新的JLabel.
有没有更优雅/有效的解决方案?是否可以将Mat对象直接绘制或转换为Canvas或Image或者可以在swing中打印为图像的任何东西?