java - Display image in mat with jframe (OpenCV 3.00) -


how display mat image in jframe. seticon() not accept mat parameter. image should used in opencv 3.00 before displaying. opencv can open mat images. there way convert image?

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

i did find code convert has highgui no longer in opencv 3.00.

matofbyte bytemat = new matofbyte(); highgui.imencode(".bmp", mat, bytemat); return new image(new bytearrayinputstream(bytemat.toarray())); 

convert mat bufferedimage, draw on panel, canvas or similar:

public static bufferedimage bufferedimage(mat m) {     int type = bufferedimage.type_byte_gray;     if ( m.channels() > 1 ) {         type = bufferedimage.type_3byte_bgr;     }     bufferedimage image = new bufferedimage(m.cols(),m.rows(), type);     m.get(0,0,((databufferbyte)image.getraster().getdatabuffer()).getdata()); // pixels     return image; } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -