本文介绍了OpenCV与Matlab:具有未读像素的不同值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在带有jpg文件的Windows 7上的Matlab(2014)和OpenCV(3.0)中遇到功能imread()的问题.

I have encountered a problem with the function imread() in Matlab (2014) and OpenCV (3.0) on Windows 7 with jpg files.

通过读取相同的文件jpg和相同的像素,我没有相同的值.

I don't have the same values by reading the same file jpg and the same pixel.

这是我的2个代码:(OpenCV代码后跟Matlab代码)和值(在OpenCV中可以看到模式调试,在Matlab中可以看到键盘)

Here are my 2 codes : (OpenCV code followed by the Matlab code) and the values I have (mode debug to see in OpenCV, keyboard in Matlab)

#include <opencv2\opencv.hpp>
#include <cstdio>

using namespace cv;
using namespace std;

int main()
{
     Mat img = imread("test.jpg");

     uchar pb = img.at<Vec3b>(0, 0).val[0];
     uchar pg = img.at<Vec3b>(0, 0).val[1];
     uchar pr = img.at<Vec3b>(0, 0).val[2];

     int d = img.depth();

     int t = img.type();
}

值:

     pixel [0,0] = (147,174,204); // = index(1,1) in the image.
     d = 0;
     t = 16;

代码Matlab:

img = imread('test.jpg');

img(1,1,:)

whos img

值:

ans(:,:,1) =
148

ans(:,:,2) =
174

ans(:,:,3) =
201

Name         Size                   Bytes  Class    Attributes
img       1920x2560x3            14745600  uint8

您知道值为何不同吗?

Have you any idea why values are different?

我在另一个帖子上看到了这样的问题,但是这个人通过阅读tiff并没有同样的深度.如您所见,我的深度相同!

I have seen on another post a problem like this but the person did not have the same depth by reading a tiff. Here as you can see I have the same depth !

在此先感谢您,如果有任何英语错误,敬请谅解.

Thank you in advance and sorry for any English mistake.

PS:我也测试了其他像素,结果相同:封闭结果,但不完全相等.

PS: I have test with other pixels too, same results : closed results but not exactly equals.

推荐答案

对于要阅读此主题的人,这是最终解释:

For people who would read this topic this is the final explanation:

它来自libjpeg的版本.版本6b(OpenCV在2.4.11之前使用此版本)的工作方式与Matlab 2014b相同.从libjpeg的版本8中,我得到了上面提到的其他结果.

It comes from the version of libjpeg. The version 6b (OpenCV used this one before 2.4.11) works in the same way as Matlab 2014b. From version 8 of libjpeg, I had the other results I mentioned above.

要解决我的问题(我使用了图像和背景的一些差异来创建蒙版,而我的问题是,在使用OpenCV(无libjeg版本6b)时图像中有些积雪,我用libjpeg 6b编译了OpenCV 3.0.(我还必须导入2个运行时库并将其放入我的项目中,该项目可在网上免费找到.)

To solve my problem (I used some difference of image and background to create a mask and my problem was that I had some snow in the image with OpenCV (without libjeg version 6b), I compiled OpenCV 3.0 with libjpeg 6b. (I also had to import 2 runtime libraries and put it in my project, found freely on the web).

我没有报告OpenCV的错误.老实说,我没有管理,即使我尝试过,我也不知道如何在他们的网站中做...

I did not report bug on OpenCV. To be honest, I did not manage, I did not understand how to do in their website even I tried...

这篇关于OpenCV与Matlab:具有未读像素的不同值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 15:42