将位图转换为灰色的JavaCV提供了重复的图像输出

时间:2017-06-28 10:16:05

标签: java android opencv javacv

我想将位图转换为灰色位图:

private Bitmap toGray(Bitmap bitmap) {

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    IplImage iplImage = IplImage.create(w, h, IPL_DEPTH_8U, 4);
    bitmap.copyPixelsToBuffer(iplImage.getByteBuffer());

    IplImage iplImageDest = IplImage.create(w, h, IPL_DEPTH_8U, 1);
    cvCvtColor(iplImage , iplImageDest , CV_RGB2GRAY);

    return toBitmap(iplImageDest);
}

private static Bitmap toBitmap(IplImage iplImage) {

    int w = iplImage.width();
    int h = iplImage.height();

    Bitmap bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ALPHA_8);
    bitmap.copyPixelsFromBuffer(iplImage.getByteBuffer());

    return bitmap;
}

输出: https://i.stack.imgur.com/btNDH.png

  • 左:原始图像
  • 右:生成的图像,问题:灰色图像复制在图像的顶部,底部是空的。

我得到这个重复的图片我做错了什么?

0 个答案:

没有答案