绘制动态折线图和饼图
#include <opencv2/opencv.hpp>
#include <vector>
void drawDynamicLineChart(cv::Mat& image, const std::vector<int>& data) {
int width = image.cols;
int height = image.rows;
cv::line(image, cv::Point(50, height - 50), cv::Point(width - 50, height - 50), cv::Scalar(255, 255, 255), 2);
cv::line(image, cv::Point(50, height - 50), cv::Point(50, 50), cv::Scalar(255, 255, 255), 2);
int numPoints = data.size();
for (int i = 0; i < numPoints - 1; ++i) {
cv::Point pt1(50 + i * (width - 100) / (numPoints - 1), height - 50 - data[i]);
cv::Point pt2(50 + (i + 1) * (width - 100) / (numPoints - 1), height - 50 - data[i + 1]);
cv::line(image, pt1, pt2, cv::Scalar(0, 255, 0), 2);
}
}
void drawDynamicPieChart(cv::Mat& image, const std::vector<float>& proportions) {
int width = image.cols;
int height = image.rows;
cv::Point center(width / 2, height / 2);
int radius = std::min(width, height) / 4;
float startAngle = 0.0;
for (float proportion : proportions) {
float endAngle = startAngle + proportion * 360.0;
cv::ellipse(image, center, cv::Size(radius, radius), 0, startAngle, endAngle, cv::Scalar(255, 0, 0), -1);
startAngle = endAngle;
}
}
int main() {
cv::Mat image(600, 800, CV_8UC3, cv::Scalar(0, 0, 0));
std::vector<int> lineChartData = {100, 200, 150, 300, 250};
std::vector<float> pieChartData = {0.2f, 0.3f, 0.1f, 0.4f};
drawDynamicLineChart(image, lineChartData);
drawDynamicPieChart(image, pieChartData);
cv::imshow("Dynamic Charts", image);
cv::waitKey(0);
return 0;
}