Android:JavaCv从Camera获取IplImage

时间:2012-06-08 16:03:29

标签: android opencv javacv

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 []数据,Camera camera)获得一个IplImage。 在我写的那里,我得到的iplimage比原来的要小得多。 有没有办法在新的iplimage上保持相同的维度?我应该避免使用子采样因子吗?我怎么能这样做?

1 个答案:

答案 0 :(得分:5)

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