Div*_*ran 3 c++ plot opencv graph image-processing
首先:我正在使用 OpenCV C++ 进行图像处理。
要求是根据一维图像的矢量值绘制图表。我参考了http://answers.opencv.org/question/73233/how-do-you-plot-graphs-in-opencv-projects/ 并找到了解决方案。这是一个可以用 OpenCV 制作的出色的作品,但是plotOpenCV 原始库不认可它。
为了找到解决方案,我检查了所有库文件并得出结论:头文件
#include opencv2/plot.hpp 不在原始 OpenCV 库(最新版本)中。它必须在一些额外的库中实现,但我想还没有上线。
这是我的代码供您参考:
#include <opencv2/plot.hpp>
int PlotGraph(Mat & data) {
Mat plot_result;
Ptr<plot::Plot2d> plot = plot::createPlot2d(data);
//Set Background color
plot->setPlotBackgroundColor(Scalar(50, 50, 50));
//Set plot line color
plot->setPlotLineColor(Scalar(50, 50, 255));
plot->render(plot_result);
imshow("plot", plot_result);
waitKey();
plot->setPlotLineColor(Scalar(50, 255, 255));
data = data / 3;
plot->render(plot_result);
imshow("plot", plot_result);
waitKey();
plot->setPlotGridColor(Scalar(255, 0, 255));
data = data * 4;
plot->render(IMREAD_UNCHANGEDplot_result);
imshow("plot", plot_result);
waitKey();
plot->setPlotTextColor(Scalar(255, 0, 0));
randu(data, 100, 400);
plot->render(plot_result);
imshow("plot", plot_result);
waitKey();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
C++ 和其他库(例如 GNU)有很多方法可以绘制图表,但是,我有点好奇,不想放弃这一点。
如果有人给我一个解决方案或建议一种在 OpenCV C++ 中绘制图形的方法,我将不胜感激。
OpenCV 中没有绘图支持。您可以使用绘图贡献模块,但它非常基本。
您可以尝试 Profactor CvPlot https://github.com/Profactor/cv-plot。(我是开发商)。它非常容易集成,完全基于 opencv,并且可以使用自定义控件进行扩展。这是绘制 cv::Mat 或使用交互式查看器显示图表的方法:
#include <CvPlot/cvplot.h>
std::vector<double> 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<CvPlot::Series>(x, y3, "-g");
axes.create<CvPlot::Series>(x, y2, "-b");
axes.create<CvPlot::Series>(x, y1, "-r");
//plot to a cv::Mat
cv::Mat mat = axes.render(300, 400);
//or show with interactive viewer
CvPlot::show("mywindow", axes);
Run Code Online (Sandbox Code Playgroud)

您可能还想尝试Leonardvandriel 的 cvplot。它的工作原理类似,但不能使用自定义绘图进行扩展。