Skip to content

Instantly share code, notes, and snippets.

@roman-smirnov
Created January 14, 2020 18:44
Show Gist options
  • Save roman-smirnov/f6c58a516ed4599c21573d26f515ae3f to your computer and use it in GitHub Desktop.
Save roman-smirnov/f6c58a516ed4599c21573d26f515ae3f to your computer and use it in GitHub Desktop.
how to plot a graph via OpenCV
#include <vector>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/plot.hpp>
int main() {
std::vector<double> x{0,1,2,3,4,5,6,7,8,9};
std::vector<double> y{0,-1,-3,-6,-7,-6,-5,-3,-1,0};
cv::Mat1d xData(x);
cv::Mat1d yData(y);
cv::Ptr<cv::plot::Plot2d> plot = cv::plot::Plot2d::create(xData, yData);
plot->setPlotSize(1920, 1080);
cv::Mat display;
plot->render(display);
cv::imshow("Graph Plot", display);
cv::waitKey(0);
return 0;
}
@roman-smirnov
Copy link
Author

Resulting Output Graph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment