opencv4 画散点图

pre

使用了opencv_contrib中的plot 模块,contrib的安装过程存在问题,如果不能解决,可以把plot.cpp/plot.h相关文件先编译一遍,之后再编译的时候带着obj。
需要一些基础的opencv配置知识,知道涉及到的模块该如何build,如何include

step1

g++ -c 将plot.cpp编译为目标文件 plot.o

后面再编译可执行的时候,就直接带着这个.o

step2

配置cvplot(https://github.com/Profactor/cv-plot)

define一个macro

编译时把inc加入到-I 中

看examples

关键代码如下

#define CVPLOT_HEADER_ONLY
#include <CvPlot/cvplot.h>

void matplotlibPlot(const int &N, float *values, vector<double> &iter_times) {
    for (auto i = 0; i < N; i++) {
        iter_times[i] /= 3.f;
    }
    vector<double> vals(values, values+N);
    Mat x(vals, CV_64F);
    Mat y(iter_times, CV_64F);
    Size x_size = x.size();
    Size y_size = y.size();
    cout << "x,y:" << x_size << "," << y_size << endl;
    
    Mat3b image(600, 1000); //关键,数据类型如果是Mat会error
    auto axes = CvPlot::plot(vals, iter_times, "o");
    axes.render(image);
    bool save_status = imwrite("/home/tangke/iter_counts.png", image);
    cout << "save image status:" << save_status << endl;
    return ;
}
posted @ 2021-12-16 20:15  ijpq  阅读(512)  评论(0编辑  收藏  举报