简体   繁体   English

如何从cv :: Mat表示QwT中的色彩图数据?

[英]How can I represent colormap data in QwT from cv::Mat?

I'm developing an application in c++ with Qt and Qwt framework for scientific plots. 我正在使用带有Qt和Qwt框架的c ++开发用于科学绘图的应用程序。 I have matrix data stored as cv::Mat , representing an image with scalar data (MxN), which needs to be visualized as a colormap. 我将矩阵数据存储为cv::Mat ,表示具有标量数据(MxN)的图像,需要将其可视化为色图。

With OpenCV it is performed using cv::applyColorMap(img,cm_img,cv::COLORMAP_JET) and cv::imshow("img name", img) , as described here 有了它OpenCV的使用进行cv::applyColorMap(img,cm_img,cv::COLORMAP_JET)cv::imshow("img name", img)所描述的, 在这里

I have tried converting cv::Mat to QImage , as described here and here but it seems not to be working properly. 我已经尝试将cv::Mat转换为QImage ,如此此处所述,但似乎无法正常工作。 When I try to show the resulting images, it doesn't make sense. 当我尝试显示生成的图像时,这没有任何意义。

From Qwt, there are some classes that looks interesting for that matter: QwtMatrixRasterData , QwtPlotSpectrogram or QwtPlotRasterItem . 在Qwt中,有些类对此很有趣: QwtMatrixRasterDataQwtPlotSpectrogramQwtPlotRasterItem

What I need as final output would be something like this. 我需要的最终输出将是这样的。 Given a matrix (MxN) with double values, calling something like imshow I get an colormap image like this 给定具有双值的矩阵(MxN),调用像imshow之类的东西,我得到一个像这样的色图图像

色彩图

We came around using QCustomPlot , sending it a QVector<double> . 我们使用QCustomPlot来了 ,向它发送了QVector<double>

The idea is to create the QVector from cv::Mat : 这个想法是从cv::Mat创建QVector

QVector<double> cvMatToQVector(const cv::Mat& mat) {
  QVector<double> image;
  auto img_ptr = img.begin<double>();

  for (; img_ptr < img.end(); img_ptr++) {
    image.append(*img_ptr) = element;
  }
  return image;
}

Then we create a QCPColorMap* colorMap and populate it with QVector vec data: 然后,我们创建一个QCPColorMap* colorMap并使用QVector vec数据进行填充:

  for (int yIndex = 0; yIndex < col; ++yIndex) {
    y_col = yIndex * col;
    for (int xIndex = 0; xIndex < row; ++xIndex) {
      z = vec.at(xIndex + y_col);
      colorMap->data()->setCell(xIndex, yIndex, z);
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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