1

この方法で作成された qCustomPlot colorMap があります。

void MainWindow::plot_color_map(QCustomPlot *customPlot, cv::Mat image)
cv::Mat rotated_matrix = cv::Mat(image.rows,image.cols,CV_64FC3);

rotated_matrix.release();   
rotate_90n(image,rotated_matrix,90);

customPlot->clearGraphs();
customPlot->clearPlottables();

customPlot->axisRect()->setupFullAxesBox(true);
customPlot->xAxis->setLabel("x");
customPlot->yAxis->setLabel("y");
customPlot->xAxis->setScaleRatio(customPlot->yAxis,1.0);

QCPColorMap *colorMap = new QCPColorMap(customPlot->xAxis,customPlot->yAxis);
customPlot->addPlottable(colorMap);

colorMap->data()->setSize(rotated_matrix.rows,rotated_matrix.cols); 
colorMap->data()->setRange(QCPRange(0,rotated_matrix.cols),QCPRange(0,rotated_matrix.rows)); 

for(int col = 0; col < rotated_matrix.cols; ++col) {
    for(int row = 0; row < rotated_matrix.rows; row++) {
        colorMap->data()->setCell(row,col,rotated_matrix.at<double>(row,col));
    }
}

QCPColorScale *colorScale = new QCPColorScale(customPlot);

double min,max;
cv::minMaxLoc(rotated_matrix,&min,&max);
qDebug() << min << " " << max;
customPlot->plotLayout()->addElement(0,1,colorScale);
colorScale->setType(QCPAxis::atRight);
colorMap->setColorScale(colorScale); 
colorMap->setGradient(QCPColorGradient::gpJet);

colorMap->rescaleDataRange();

QCPMarginGroup *marginGroup = new QCPMarginGroup(customPlot);
customPlot->axisRect()->setMarginGroup(QCP::msBottom | QCP::msTop, marginGroup);
colorScale->setMarginGroup(QCP::msBottom | QCP::msTop, marginGroup);

customPlot->rescaleAxes();
customPlot->replot();

colorMap は適切に表示され、スケール範囲は、コンソールに出力した「最小」値と「最大」値に一致します。

ただし、cv::Mat イメージのデータを変更しても、スケールは更新されません。

たとえば、最初のデータ範囲が 0.2 から 7.3 の場合、その後プロットするデータを選択しても、スケールは 0.2 から 7.3 に固定され、新しいデータ セットを反映するように変更されません。

データ範囲に合わせてスケールを自動更新する方法はありますか?

プログラムを閉じて再度開くと、最初に関数を実行すると、スケールは常に正しくなり、別の画像がプロットされた後にのみ変更されません。

ありがとうミッチ

4

0 に答える 0