简体   繁体   English

Java JAI BufferedImage与C ++ OpenCV Mat读了吗?

[英]Java JAI BufferedImage versus C++ OpenCV Mat imread?

In Java: 在Java中:

I am reading an image using JAI: 我正在使用JAI读取图像:

 BufferedImage image = javax.imageio.ImageIO.read(new File("path to JPG image"));

Then, I look at the rgb value of the pixel (0,2): 然后,我看一下像素(0,2)的rgb值:

System.out.println("pixel[0][2]="+(new Color(image.getRGB(2, 0))));

In C++ OpenCV: 在C ++ OpenCV中:

Mat image = imread("path to the same JPG image");
image.convertTo(image, CV_32S);
cout <<" r value of pixel[0][2] "<< image.at<Vec3i>(0, 2)[2] << "\n";

The values are different: r value in Java is 156 and in C++ is 155. Why? 值是不同的:Java中的r值为156,C ++中的r值为155。为什么?

I think this has to do with the format of the image, not with Java or OpenCV. 我认为这与图像的格式有关,而不与Java或OpenCV有关。 JPEG is lossy compression, so when decoding the data you may get different outputs for the same image. JPEG是有损压缩,因此在解码数据时,同一张图像可能会获得不同的输出。 That will depend on the decoder you are using to read the image information. 这将取决于您用来读取图像信息的解码器。 The issue you are experimenting is similar to the one described in the below question. 您正在尝试的问题与以下问题中描述的问题类似。

Reading jpg file in OpenCV vs C# Bitmap 在OpenCV和C#位图中读取jpg文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM