package org.ski;
import java.awt.image.BufferedImage;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;
public class Mat2Image {
Mat mat = new Mat();
BufferedImage img;
byte[] dat;
public Mat2Image() {}
public Mat2Image(Mat mat) {
getSpace(mat);
}
public void getSpace(Mat mat) {
this.mat = mat;
int w = mat.cols(), h = mat.rows();
if (dat == null || dat.length != w * h * 3)
dat = new byte[w * h * 3];
if (img == null || img.getWidth() != w ||
img.getHeight() != h)
img = new BufferedImage(w, h,
BufferedImage.TYPE_3BYTE_BGR);
}
BufferedImage getImage(Mat mat){
getSpace(mat);
mat.get(0, 0, dat);
img.getRaster().setDataElements(0, 0,
img.getWidth(), img.getHeight(), dat);
return img;
}
static{
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
}
Syntax Highlighting Experiments
Monday, October 28, 2013
A Class That Converts OpenCV BGR to Java BufferedImage
Sunday, October 27, 2013
cpp & java
#include < iostream > using namespace std; class Rect{ int x, y, width,height; int getArea(){ return width*height;} }
Subscribe to:
Posts (Atom)