opencv4.x 中的plot函数绘制二维Mat
发现一个好玩的二维图像绘制函数,与大家共同欣赏:)
参考网址:OpenCV4入门061:使用plot2d绘制折线图 - 食铁兽 (feater.top)
头文件:
#include<opencv2/plot.hpp>
动态库:
-llibopencv_plot454d
int main() { //准备一行51列的数据位置 Mat data_x(1, 51, CV_64F); Mat data_y(1, 51, CV_64F); //填充模拟数据 for (int i = 0; i < data_x.cols; i++) { double x = (i - data_x.cols / 2); data_x.at<double>(0, i) = x; data_y.at<double>(0, i) = x * x * x; } std::cout << "data_x : " << data_x << std::endl; std::cout << "data_y : " << data_y << std::endl; Mat plot_result; Ptr<plot::Plot2d> plot=plot::Plot2d::create(data_x,data_y); plot->render(plot_result); imshow("plot 2d data in default way!",plot_result); //自定义参数 plot->setShowText(false); plot->setShowGrid(false); plot->setPlotBackgroundColor(Scalar(255, 200, 200)); plot->setPlotLineColor(Scalar(255, 0, 0)); plot->setPlotLineWidth(2); plot->setInvertOrientation(true);//左右颠倒绘制 plot->render(plot_result);//根据参数进行渲染 imshow("The plot rendered with some of custom visualization options", plot_result); waitKey(); return 0; }
输出结果: