When using QT and OPENCV mixed programming, we sometimes need to convert between the two picture classes Cv::mat and Qimage, and the following code references this post on the Web:
//##### Cv::mat---> Qimage #####//Shallow CopyQimage Mat2qimage_ref (Cv::mat &m, Qimage::format Format) { returnqimage (M.data, M.cols, M.rows, m.step, format);}//Deep CopyQimage mat2qimage_cpy (Cv::mat &m, Qimage::format Format) { returnqimage (M.data, M.cols, M.rows, M.step, format). copy ();//##### qimage---> Cv::mat #####//Shallow CopyCv::mat Qimage2mat_ref (Qimage &img,intformat) { returnCv::mat (Img.height (), Img.width (), Format, Img.bits (), Img.bytesperline ());}//Deep CopyCv::mat Qimage2mat_ref (Qimage &img,intformat) { returnCv::mat (Img.height (), Img.width (), format, const_cast<uchar*>(Img.bits ()), Img.bytesperline ()). Clone ();
Convert between Cv::mat and qimage two picture class conversions