OpenCV vs Matlab : Different Values on pixels with imread

醉酒当歌 提交于 2019-11-27 20:13:50
Nablast

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

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.

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).

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...

This code gives the correct values for your example image test2.jpg:

#include <opencv2/highgui/highgui.hpp>
#include <iostream>

int main()
{
    auto img = cv::imread("test2.jpg");
    auto pixel = img.at<cv::Vec3b>(85, 85);
    std::cout << (int)pixel[0] << "\t" << (int)pixel[1]
              << "\t" << (int)pixel[2] << std::endl;
}

Output:

118     105     91

The OpenCV version here is 2.4.10. I get the same result when using your code. I suppose there is a bug somewhere that is beyond your influence.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!