0

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?

C Banana
  • 45
  • 9

1 Answers1

6

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
rafix07
  • 20,001
  • 3
  • 20
  • 33
  • This resulted in `error: conversion from ‘std::basic_ostringstream::__string_type {aka std::basic_string}’ to non-scalar type ‘QString’ requested` but it's got me damn close so thank you. I'll put my solution up as the answer. – C Banana Feb 01 '18 at 11:38