Drawing and Plotting graph in OpenCV

后端 未结 5 1410
春和景丽
春和景丽 2020-12-14 23:09

Does OpenCV provide a function on how to draw and plot a graph?

I found this link by Shervin Emami http://www.shervinemami.info/graphs.html which was created by him

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 23:55

    No. It does not. There is a plot contrib module, but it is very basic.

    You could try Profactor CvPlot https://github.com/Profactor/cv-plot. (I am the developer). It is very easy to integrate, purely opencv based and can be extended with custom controls. This is how you can plot to a cv::Mat or show a diagram with an interactive viewer:

    #include 
    std::vector x(20*1000), y1(x.size()), y2(x.size()), y3(x.size());
    for (size_t i = 0; i < x.size(); i++) {
        x[i] = i * CV_2PI / x.size();
        y1[i] = std::sin(x[i]);
        y2[i] = y1[i] * std::sin(x[i]*50);
        y3[i] = y2[i] * std::sin(x[i]*500);
    }
    auto axes = CvPlot::makePlotAxes();
    axes.create(x, y3, "-g");
    axes.create(x, y2, "-b");
    axes.create(x, y1, "-r");
    
    //plot to a cv::Mat
    cv::Mat mat = axes.render(300, 400);
    
    //or show with interactive viewer
    CvPlot::show("mywindow", axes);
    

    CvPlot

    You may also want to try Leonardvandriel's cvplot. It works similar but cannot be extended with custom drawables.

提交回复
热议问题