Convert OpenCV Mat object to BufferedImage

后端 未结 2 1015
陌清茗
陌清茗 2021-02-15 18:43

I am trying to create a helper function using OpenCV Java API that would process an input image and return the output byte array. The input image is a jpg file saved in the comp

2条回答
  •  既然无缘
    2021-02-15 19:29

    I used this kind of code to convert Mat object to Buffered Image.

    static BufferedImage Mat2BufferedImage(Mat matrix)throws Exception {        
        MatOfByte mob=new MatOfByte();
        Imgcodecs.imencode(".jpg", matrix, mob);
        byte ba[]=mob.toArray();
    
        BufferedImage bi=ImageIO.read(new ByteArrayInputStream(ba));
        return bi;
    }
    

提交回复
热议问题