java rgb转灰度图_Java和OpenCV无法将RGB .gif图像转换为灰色

我想使用

Java和OpenCV将图片从RGB转换为GRAY

所有扩展图像都正常工作,我拍摄灰色图像,

如果我制作.GIF图像(不移动)它会给我这个错误:

OpenCV错误:在cv :: cvtColor中断言失败(scn == 3 || scn == 4)

java代码:

Mat scrImg = Highgui.imread(path);

Mat dstImg = new Mat(scrImg.rows(),scrImg.cols(),scrImg.type());

Imgproc.cvtColor(scrImg, dstImg, Imgproc.COLOR_RGB2GRAY);

private static BufferedImage Mat2BufferedImage(Mat matrix){

BufferedImage bimOut;

int type;

if(matrix.channels() == 1)

type = BufferedImage.TYPE_BYTE_GRAY;

else

type = BufferedImage.TYPE_3BYTE_BGR;

int dataLength = matrix.channels()*matrix.cols()*matrix.rows();

byte [] buffer = new byte[dataLength];

bimOut = new BufferedImage(matrix.cols(),matrix.rows(),type);

matrix.get(0,0,buffer);

final byte[] bimPixels = ((DataBufferByte) bimOut.getRaster().getDataBuffer()).getData();

System.arraycopy(buffer, 0, bimPixels, 0, buffer.length);

return bimOut;

}

Currently, the following file formats are supported:

Windows bitmaps – *.bmp, *.dib (always supported)

JPEG files – *.jpeg, *.jpg, *.jpe (see the Notes section)

JPEG 2000 files – *.jp2 (see the Notes section)

Portable Network Graphics – *.png (see the Notes section)

WebP – *.webp (see the Notes section)

Portable image format – *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported)

Sun rasters – *.sr, *.ras (always supported)

TIFF files – *.tiff, *.tif (see the Notes section)

OpenEXR Image files – *.exr (see the Notes section)

Radiance HDR – *.hdr, *.pic (always supported)

Raster and Vector geospatial data supported by Gdal (see the Notes section)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值