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
Post a Comment