From cbda9b332bb29b2761b28623ca8a2cdb4e778518 Mon Sep 17 00:00:00 2001 From: berak Date: Mon, 24 Apr 2017 11:53:50 +0200 Subject: [PATCH] imgcodecs: fix webp IMREAD_GRAYSCALE loading --- modules/imgcodecs/src/grfmt_webp.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/imgcodecs/src/grfmt_webp.cpp b/modules/imgcodecs/src/grfmt_webp.cpp index 981ce7bcc0..1281d832e1 100644 --- a/modules/imgcodecs/src/grfmt_webp.cpp +++ b/modules/imgcodecs/src/grfmt_webp.cpp @@ -162,6 +162,8 @@ bool WebPDecoder::readData(Mat &img) { if( m_width > 0 && m_height > 0 ) { + bool convert_grayscale = (img.type() == CV_8UC1); // IMREAD_GRAYSCALE requested + if (img.cols != m_width || img.rows != m_height || img.type() != m_type) { img.create(m_height, m_width, m_type); @@ -184,6 +186,10 @@ bool WebPDecoder::readData(Mat &img) if(res_ptr == out_data) { + if (convert_grayscale) + { + cvtColor(img, img, COLOR_BGR2GRAY); + } return true; } }