简体   繁体   中英

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.

I have downloaded both opencv and javacv, and extracted it into C drive. 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.

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();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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