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
A rather crude but do-it-yourself approach, would be entail plotting the line graph on cv::Mat image:
template
cv::Mat plotGraph(std::vector& vals, int YRange[2])
{
auto it = minmax_element(vals.begin(), vals.end());
float scale = 1./ceil(*it.second - *it.first);
float bias = *it.first;
int rows = YRange[1] - YRange[0] + 1;
cv::Mat image = Mat::zeros( rows, vals.size(), CV_8UC3 );
image.setTo(0);
for (int i = 0; i < (int)vals.size()-1; i++)
{
cv::line(image, cv::Point(i, rows - 1 - (vals[i] - bias)*scale*YRange[1]), cv::Point(i+1, rows - 1 - (vals[i+1] - bias)*scale*YRange[1]), Scalar(255, 0, 0), 1);
}
return image;
}
Usage example:
vector numbers(100);
std::iota (numbers.begin(), numbers.end(), 0);
int range[2] = {0, 100};
cv::Mat lineGraph = plotGraph(numbers, range);
One can then use imshow or Image Watch to view the graph