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