protected IplImage processImage(byte[] data, int width, int height) {
int f = 4;// SUBSAMPLING_FACTOR;
// First, downsample our image and convert it into a grayscale IplImage
IplImage grayImage = IplImage.create(width / f, height / f, IPL_DEPTH_8U, 1);
int imageWidth = grayImage.width();
int imageHeight = grayImage.height();
int dataStride = f * width;
int imageStride = grayImage.widthStep();
ByteBuffer imageBuffer = grayImage.getByteBuffer();
for (int y = 0; y < imageHeight; y++) {
int dataLine = y * dataStride;
int imageLine = y * imageStride;
for (int x = 0; x < imageWidth; x++) {
imageBuffer.put(imageLine + x, data[dataLine + f * x]);
}
}
return grayImage;
}
我应该从 onPreviewFrame(byte[] data, Camera camera) 获取 IplImage。 按照我在那里写的方式,我得到的 iplimage 比原始图像小得多。 有什么办法可以让新的iplimage保持相同的尺寸吗?我应该避免二次采样因子吗?我该怎么做?
最佳答案
是的,只要设置f = 1
,它就不会进行二次采样。
关于Android:JavaCv 从相机获取 IplImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10952317/