简体   繁体   中英

OpenCV Mat to Qt QString

I'm using opencv in a Qt app. I've seen some generic c++ ways of printing out the values of a Mat and have done so with

cout << "myMat = "<< endl << " "  << myMat << endl << endl;

Ideally I could have a QString with the contents of this Mat. Is there a neat way to do this?

You can use ostringstream and its method str() to get string which you can pass as parameter to QString constructor.

    cv::Mat M(2,2, CV_8UC3, cv::Scalar(0,0,255));
    ostringstream oss;
    oss << "M = " << endl << " " << M << endl;
    QString matContent(oss.str()); // QT3
    QString matContent2(oss.str().c_str()); // QT4/5 (const char*) constructor

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM