由于opencv中只有一些基本的图形的绘制,包括直线,矩形,椭圆,圆形等简单图形的绘制,但是在我们的学习中,经常会使用到其他函数的图像的绘制,这种情况该怎么办? 利用曲线可以看成无数段直线组成的性质,我们使用大量的首尾相连的线段来表示复杂的曲线。 详细的opencv代码如下:
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "cmath"
using namespace cv;
#define WINDOW_WIDTH 600
void Drawline(Mat img,Point start,Point end)
{
int thickness = 1;
int linetype = 8;
line(img, start, end, Scalar(250, 220, 0), thickness, linetype);
}
int main()
{
Mat img1(600, 600, CV_8UC3, Scalar::all(0));
double x0 = 0, y0 = 300, x;
double y;
for (x = 0; x < 600; x++)
{
y = 100*sin(0.08*x)+300;
Point S(x0, y0);
Point E(x, y);
Drawline(img1, S, E);
x0 = x; y0 = y;
}
imshow("Sin 函数图像", img1);
waitKey();
return 0;
}