Convert between Cv::mat and qimage two picture class conversions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.