OpenCV—绘图相关函数
1、circle
CV_EXPORTS_W void circle(InputOutputArray img, // 输入图像
Point center, // 圆心
int radius, // 半径
const Scalar& color, // 颜色
int thickness = 1, // 线宽
int lineType = LINE_8, // 线型 4 or 8
int shift = 0);
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat frame = cv::imread("G:\\proj\\opencv\\data\\pic\\1.JPG");
cv::circle(frame,Point(334,246),200,Scalar(10,234,34),1); //thickness = -1 实心的
imshow("1",frame);
waitKey(0);
return 0;
}
令 thickness = -1, 实心的
2 、ellipse() 椭圆
CV_EXPORTS_W void ellipse(InputOutputArray img, // 图像
Point center, // 中心点
Size axes, // 长轴,短轴
double angle, // 角度
double startAngle, // 起始角
double endAngle, // 结束角
const Scalar& color, // 颜色
int thickness = 1,
int lineType = LINE_8,
int shift = 0);
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = cv::Mat::zeros(640,640,CV_8UC3);
cv::ellipse(img,Point(320,320),Size(100,50),0,0,360,Scalar(10,234,34));
imshow("2",img);
waitKey(0);
return 0;
}
3、fillPoly()填充多边形
CV_EXPORTS void fillPoly(Mat& img,
const Point** pts, // 二维点数组
const int* npts, // 点个数
int ncontours, //
const Scalar& color, // 颜色
int lineType = LINE_8,
int shift = 0,
Point offset = Point() );
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = cv::Mat::zeros(640,640,CV_8UC3);
Point poly_points[1][5];
poly_points[0][0] = Point(330,100);
poly_points[0][1] = Point(280, 150);
poly_points[0][2] = Point(280, 250);
poly_points[0][3] = Point(380, 250);
poly_points[0][4] = Point(380, 150);
const Point* ppt[1] = { poly_points[0] };
int npt[] = {5};
cv::fillPoly(img, ppt, npt, 1,Scalar(0,240,0));
imshow("Test", img);
waitKey(0);
return 0;
}
4、line()直线
CV_EXPORTS_W void line(InputOutputArray img,
Point pt1,
Point pt2,
const Scalar& color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0);
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = cv::Mat::zeros(640,640,CV_8UC3);
cv::line(img,Point(100,100),Point(400,400),Scalar(100,10,100),2);
imshow("3", img);
waitKey(0);
return 0;
}
5、rectangle() 画矩形
CV_EXPORTS_W void rectangle(InputOutputArray img,
Point pt1,
Point pt2,
const Scalar& color,
int thickness = 1,
int lineType = LINE_8,
int shift = 0);
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = cv::Mat::zeros(640,640,CV_8UC3);
cv::line(img,Point(100,100),Point(400,400),Scalar(100,100,100),2);
cv::rectangle(img,Point(100,100),Point(400,400),Scalar(100,10,100),2);
imshow("3", img);
waitKey(0);
return 0;
}