Ask Your Question
0

cvtColor vs reading image directly

asked 2018-06-05 01:35:03 -0600

charles1208 gravatar image

updated 2018-06-05 01:42:12 -0600

I have the following:

string input = "test.jpg";

cv::Mat tmp = cv::imread(input, CV_LOAD_IMAGE_COLOR);
cv::Mat img1;
cv::cvtColor(tmp, img1, CV_BGR2GRAY);

cv::Mat img2 = cv::imread(input, cv::IMREAD_GRAYSCALE); 

isMatEqual(img1, img2);

where isMatEqual():

bool isMatEqual(const cv::Mat & a, const cv::Mat & b)
{
    if ( (a.rows != b.rows) || (a.cols != b.cols) )
        return false;
    cv::Scalar s = sum( a - b );
    return (s[0]==0) && (s[1]==0) && (s[2]==0);
}

However I am not getting an equality when comparing the 2 images. If I am forced to read the image in first and then do a cvtColor() transform to grayscale, what would be a correct parameter to set such that img1 == img2?

Edit: I saw a similar question: https://stackoverflow.com/questions/7... but I am unable to reproduce the answer given with my input.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-06-05 01:41:48 -0600

LBerger gravatar image

updated 2018-06-05 01:48:08 -0600

see https://github.com/opencv/opencv/issu... :

You have to use CV_LOAD_IMAGE_COLOR in all cases

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-06-05 01:35:03 -0600

Seen: 419 times

Last updated: Jun 05 '18