标签:rgb stdio.h include rectangle 画圆 几何 net fill 小数点
绘制点和圆
void cvCircle( CvArr* img, CvPoint center, int radius, CvScalar color,
int thickness=1, int line_type=8, int shift=0 );
画圆画点都是使用circle()函数来画,点就是圆,我们平常所说的圆只不过是半径大一点而已。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
//画圆画点都是使用circle()函数来画,点就是圆,我们平常所说的圆只不过是半径大一点而已。
int main()
{
Mat img = imread("lol16.jpg");
//画空心点
Point p(20, 20);//初始化点坐标为(20,20)
circle(img, p, 2, Scalar(0, 255, 0)); //第三个参数表示点的半径,第四个参数选择颜色。这样子我们就画出了绿色的空心点
//这种初始化点的方式也可以
Point p2;
p2.x = 100;
p2.y = 100;
//画实心点
circle(img, p2, 3,Scalar(255,0,0),-1); //第五个参数我设为-1,表明这是个实点。
//画空心圆
Point p3(300, 300);
circle(img,p3,100,Scalar(0,0,255),3);//第五个参数我们调高点,让线更粗
//画实心圆
Point p4;
p4.x = 600;
p4.y = 600;
circle(img, p4, 100, Scalar(120, 120, 120), - 1);
imshow("画点画圆", img);
waitKey();
return 0;
}
绘制椭圆
void ellipse(Mat& img, Point center,Size axes, double angle, double startAngle, double endAngle, const Scalar& color,int thickness=1, int lineType=8, int shift=0)
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("lol16.jpg");
int thickness = 3;
int lineType = 8;
double angle = 30; //椭圆旋转角度
//第三个参数Size中的两个参数分别是横轴长、纵轴长。
//同理,thickness若是小于0,表示实心
ellipse(img,Point(100, 100),Size(90, 60),angle,0,360,Scalar(255, 255, 0),thickness,lineType);
imshow("画椭圆", img);
waitKey();
return 0;
}
绘制矩形
void rectangle(Mat& img,Rect rec, const Scalar&color, intthickness=1, intlineType=8,intshift=0 )
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("lol16.jpg");
Rect r(250, 250, 120, 200);
rectangle(img, r, Scalar(0, 255, 255), 3);
imshow("画矩形", img);
waitKey();
return 0;
}
绘制直线
void line(InputOutputArray img, Point pt1, Point pt2, const Scalar& color,
int thickness = 1, int lineType = LINE_8, int shift = 0);
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("lol16.jpg");
Point p1(100, 100);
Point p2(758, 50);
line(img, p1, p2, Scalar(33, 33, 133), 2);
//画第二条线
line(img, Point(300, 300), Point(758, 300), Scalar(89, 90, 90), 3);
imshow("画矩形", img);
waitKey();
return 0;
}
最后来个综合的图形展示。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
Mat img = Mat::zeros(Size(800,600), CV_8UC3);
img.setTo(255);
Point p1(100, 100);
Point p2(758, 50);
line(img, p1, p2, Scalar(0, 0, 255), 2);
line(img, Point(300, 300), Point(758, 400), Scalar(0, 255, 255), 3);
Point p(20, 20);//初始化点坐标为(20,20)
circle(img, p, 2, Scalar(0, 255, 0),-1);
Point p4;
p4.x = 600;
p4.y = 600;
circle(img, p4, 100, Scalar(120, 120, 120), -1);
int thickness = 3;
int lineType = 8;
double angle = 30; //椭圆旋转角度
ellipse(img, Point(100, 100), Size(90, 60), angle, 0, 360, Scalar(255, 255, 0), thickness, lineType);
Rect r(250, 250, 120, 200);
rectangle(img, r, Scalar(0, 255, 255), 3);
imshow("大杂烩", img);
waitKey();
return 0;
}
标签:rgb stdio.h include rectangle 画圆 几何 net fill 小数点
原文地址:http://www.cnblogs.com/xieyulin/p/7060894.html