简体   繁体   English

使用javacv 1.4.2在框架中打开图像

[英]Open Image in a frame using javacv 1.4.2

I am new to javacv and want to know how to open the image in a frame using javacv 1.4.2 and opencv 3.4.2. 我是javacv的新手,并想知道如何使用javacv 1.4.2和opencv 3.4.2在框架中打开图像。

I have downloaded both opencv and javacv, and extracted it into C drive. 我已经下载了opencv和javacv,并将其解压缩到C驱动器中。 Also loaded it into Libraries. 还将其加载到库中。

This the code i tried. 这是我尝试的代码。

Mat image = imread(filename);
    if (image != null) {
        GaussianBlur(image, image, new Size(3, 3), 0);
        imwrite(filename, image);
    }

I just want to show the image in the frame before saving it to the disk. 我只想在将图像保存到磁盘之前在框架中显示图像。

Code block for show Mat in frame. 在框架中显示Mat的代码块。

public static void showResult(Mat img)
{   
    MatOfByte matOfByte = new MatOfByte();
    Imgcodecs.imencode(".jpg", img, matOfByte);
    byte[] byteArray = matOfByte.toArray();
    BufferedImage bufImage = null;
    try
    {
        InputStream in = new ByteArrayInputStream(byteArray);
        bufImage = ImageIO.read(in);
        JFrame frame = new JFrame();
        frame.getContentPane().add(new JLabel(new ImageIcon(bufImage)));
        frame.pack();
        frame.setVisible(true);
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM