That indeed seems to be the case. But this is very interesting for Grayscale. RGB888 is fine. Maybe this is more a OpenCV question, why would the BPL not equal pixels per line?
Many thanks to all who replied.
Sent: Thursday, June 20, 2019 at 5:33 PM
From: "René Hansen" <ren...@gmail.com>
To: "Jason H" <jh...@gmx.com>
Cc: "interestqt-project.org" <interest@qt-project.org>
Subject: Re: [Interest] Problem with cv::Mat grayscale to QImage
From: "René Hansen" <ren...@gmail.com>
To: "Jason H" <jh...@gmx.com>
Cc: "interestqt-project.org" <interest@qt-project.org>
Subject: Re: [Interest] Problem with cv::Mat grayscale to QImage
You might need to set the bytesPerLine of the QImage to match the step of cv::Mat. I seem to recall having a similar issue once, converting between a four and three bytes per pixel formats, e.g. if the cv::Mat is in CV_8UC4.
/René
On Thu, 20 Jun 2019 at 23:05, Jason H <jh...@gmx.com> wrote:
Simple code:
cv::Mat left_image = cv::imread(filename, cv::IMREAD_COLOR );
cv::cvtColor(mat, mat, cv::COLOR_BGR2GRAY);
cv::imwrite("dummy_gray_cv.png", left_image); // ok
QImage test((unsigned char*) left_image.data, left_image.cols, left_image.rows, QImage::Format_Grayscale8);
test.save("dummy_gray_qt.png"); // skewed
However the dummy_gray_qt.png image is not aligned correctly, it's skewed as if bytes are missing/being skipped.
I have to convert it back to color to work:
cv::Mat dst;
cv::cvtColor(left_image, dst, cv::COLOR_GRAY2BGRA);
QImage result = QImage((unsigned char*) dst.data, dst.cols, dst.rows, QImage::Format_RGB32);
result.save("dummy_color_qt.png")
Is there a way I can avoid needing cv::cvtColor(left_image, dst, cv::COLOR_GRAY2BGRA)?
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
Never fear, Linux is here.
_______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest