public static void showResult(Mat img) { Imgproc.resize(img, img, new Size(640, 480)); MatOfByte matOfByte = new MatOfByte(); Highgui.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(); } }
public byte[] toArray() { int num = checkVector(_channels, _depth); if(num < 0) throw new RuntimeException("Native Mat has unexpected type or size: " + toString()); byte[] a = new byte[num * _channels]; if(num == 0) return a; get(0, 0, a); //TODO: check ret val! return a; }
protected MatOfByte(long addr) { super(addr); if( !empty() && checkVector(_channels, _depth) < 0 ) throw new IllegalArgumentException("Incompatible Mat"); //FIXME: do we need release() here? }
public static MatOfByte fromNativeAddr(long addr) { return new MatOfByte(addr); }
public List<Byte> toList() { byte[] a = toArray(); Byte ab[] = new Byte[a.length]; for(int i=0; i<a.length; i++) ab[i] = a[i]; return Arrays.asList(ab); } }
public MatOfByte(byte...a) { super(); fromArray(a); }
private static Mat streamToMat(InputStream stream) throws IOException { byte[] data = new byte[1024]; MatOfByte chunk = new MatOfByte(); MatOfByte buf = new MatOfByte(); int read; while ((read = stream.read(data)) > 0) { chunk.fromArray(data); Mat subchunk = chunk.submat(0, read, 0, 1); buf.push_back(subchunk); } return buf; }
public byte[] toArray() { int num = checkVector(_channels, _depth); if(num < 0) throw new RuntimeException("Native Mat has unexpected type or size: " + toString()); byte[] a = new byte[num * _channels]; if(num == 0) return a; get(0, 0, a); //TODO: check ret val! return a; }
protected MatOfByte(long addr) { super(addr); if( !empty() && checkVector(_channels, _depth) < 0 ) throw new IllegalArgumentException("Incompatible Mat"); //FIXME: do we need release() here? }
public static MatOfByte fromNativeAddr(long addr) { return new MatOfByte(addr); }
public List<Byte> toList() { byte[] a = toArray(); Byte ab[] = new Byte[a.length]; for(int i=0; i<a.length; i++) ab[i] = a[i]; return Arrays.asList(ab); } }
public void fromList(List<Byte> lb) { if(lb==null || lb.size()==0) return; Byte ab[] = lb.toArray(new Byte[0]); byte a[] = new byte[ab.length]; for(int i=0; i<ab.length; i++) a[i] = ab[i]; fromArray(a); }
public byte[] toArray() { int num = checkVector(_channels, _depth); if(num < 0) throw new RuntimeException("Native Mat has unexpected type or size: " + toString()); byte[] a = new byte[num * _channels]; if(num == 0) return a; get(0, 0, a); //TODO: check ret val! return a; }
protected MatOfByte(long addr) { super(addr); if( !empty() && checkVector(_channels, _depth) < 0 ) throw new IllegalArgumentException("Incompatible Mat"); //FIXME: do we need release() here? }
Mat image_tmp = your image MatOfByte matOfByte = new MatOfByte(); Highgui.imencode(".jpg", image_tmp, matOfByte); byte[] byteArray = matOfByte.toArray(); BufferedImage bufImage = null; try { InputStream in = new ByteArrayInputStream(byteArray); bufImage = ImageIO.read(in); } catch (Exception e) { e.printStackTrace(); }
public static MatOfByte fromNativeAddr(long addr) { return new MatOfByte(addr); }
public List<Byte> toList() { byte[] a = toArray(); Byte ab[] = new Byte[a.length]; for(int i=0; i<a.length; i++) ab[i] = a[i]; return Arrays.asList(ab); } }