2
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 上保持相同的尺寸?我应该避免二次抽样因素吗?我怎样才能做到这一点?

4

1 回答 1

5

是的,只需设置f = 1,它就不会进行二次采样。

于 2012-06-09T08:57:15.427 回答