Ask Your Question
1

imread, imwrite does not give similar image

asked 2018-05-30 03:31:58 -0600

charles1208 gravatar image

I have the following code:

string src = "a.jpg";
string dest = "a_out.jpg";

cv::Mat im = cv::imread(src, CV_LOAD_IMAGE_COLOR);
cv::imwrite(dest, im);
cv::Mat im2 = cv::imread(dest, CV_LOAD_IMAGE_COLOR);
isMatEqual(im,im2);

where:

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 get a return that is false. Is there something wrong my reading/writing of the images?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-05-30 03:50:40 -0600

berak gravatar image

updated 2018-05-30 05:05:15 -0600

it's not your code.

.jpg is a "lossy" format, you'll never get back exactly, what you wrote.

if you need that kind of exactness, stick with lossless codecs, like .png or uncompressed images, like .bmp

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-05-30 03:31:58 -0600

Seen: 161 times

Last updated: May 30 '18