int width = bi.getWidth();
int height = bi.getHeight();
opencv_core.Mat mat = new opencv_core.Mat(new opencv_core.Size(width,height), CV_8UC3);
int[] data = ImageJavaUtils.getRGBPixels(bi);
UByteRawIndexer idx = mat.createIndexer();
for(int i = 0;i<height;i++){
for(int j = 0;j<width;j++){
idx.put(i,j,data[j+i*width]);
}
}
I did use tradition javacv way but in my function of project it does not working, even I must saved the image into HDD after use imread and use toMat below then it works. So I must be
find out other way to convert same as above but not working. Can you show me where I wrong?
public static opencv_core.Mat toMat(BufferedImage img){
OpenCVFrameConverter.ToIplImage cv = new OpenCVFrameConverter.ToIplImage();
Java2DFrameConverter jcv = new Java2DFrameConverter();
return cv.convertToMat(jcv.convert(img));
}
I did use tradition javacv way but in my function of project it does not working, even I must saved the image into HDD after use imread and use toMat below then it works. So I must befind out other way to convert same as above but not working. Can you show me where I wrong?public static opencv_core.Mat toMat(BufferedImage img){ OpenCVFrameConverter.ToIplImage cv = new OpenCVFrameConverter.ToIplImage(); Java2DFrameConverter jcv = new Java2DFrameConverter(); return cv.convertToMat(jcv.convert(img)); }
When you say "it does not working", what isn't working? What
happens?
Here I played with not working:Object B: BufferedImage bi,....class A(Object B){BufferedImage process = preprocess(B);
Object B: BufferedImage bi,....class A(Object B){BufferedImage process = preprocess(B);