(14)Air Band OpenCV2.4.13_基础作图
来源:互联网 发布:季度数据季节调整 编辑:程序博客网 时间:2024/06/10 05:11
本文是对OpenCV2.4.13文档的部分翻译,作个人学习之用,并不完整。
首先介绍两个结构:
Point
一个二维点,可以如下定义:
Point pt;
pt.x=10;
pt.y=8;
或:
Point pt=Point(10,8);
Scalar
一个四元素向量,常用于传递像素值,这里我们用于表示BGR颜色值(3参数),最后一个元素用不到可以不定义。
Scalar(a,b,c);//定义了Blue=a,Green=b,Red=c
#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>#define w 400using namespace cv;/// 作图函数void MyEllipse( Mat img, double angle );void MyFilledCircle( Mat img, Point center );void MyPolygon( Mat img );void MyLine( Mat img, Point start, Point end );int main( void ){ /// 窗口名称 char atom_window[] = "Drawing 1: Atom"; char rook_window[] = "Drawing 2: Rook"; /// 创建空图像 Mat atom_image = Mat::zeros( w, w, CV_8UC3 ); Mat rook_image = Mat::zeros( w, w, CV_8UC3 ); /// 1. 画一个简单的圆 /// ----------------------- /// 1.a. 创建椭圆 MyEllipse( atom_image, 90 );//第二个参数为角度 MyEllipse( atom_image, 0 ); MyEllipse( atom_image, 45 ); MyEllipse( atom_image, -45 ); /// 1.b. 创建圆 MyFilledCircle( atom_image, Point( w/2, w/2) );//第二个参数为圆心 /// 2. 画一个车(国际象棋) /// ------------------ /// 2.a. 创建一个凸多边形 MyPolygon( rook_image ); /// 2.b. 创建矩形 rectangle( rook_image, Point( 0, 7*w/8 ), Point( w, w), Scalar( 0, 255, 255 ), -1, 8 ); /// 2.c. 创建线 MyLine( rook_image, Point( 0, 15*w/16 ), Point( w, 15*w/16 ) ); MyLine( rook_image, Point( w/4, 7*w/8 ), Point( w/4, w ) ); MyLine( rook_image, Point( w/2, 7*w/8 ), Point( w/2, w ) ); MyLine( rook_image, Point( 3*w/4, 7*w/8 ), Point( 3*w/4, w ) ); /// 3. 显示图像 imshow( atom_window, atom_image ); moveWindow( atom_window, 0, 200 ); imshow( rook_window, rook_image ); moveWindow( rook_window, w, 200 ); waitKey( 0 ); return(0);}/// 函数定义/** * @function MyEllipse * @brief Draw a fixed-size ellipse with different angles */void MyEllipse( Mat img, double angle ){ int thickness = 2; int lineType = 8; ellipse( img, Point( w/2, w/2 ), Size( w/4, w/16 ), angle, 0, 360, Scalar( 255, 0, 0 ), thickness, lineType );}/** * @function MyFilledCircle * @brief Draw a fixed-size filled circle */void MyFilledCircle( Mat img, Point center ){ int thickness = -1; int lineType = 8; circle( img, center, w/32, Scalar( 0, 0, 255 ), thickness, lineType );}/** * @function MyPolygon * @function Draw a simple concave polygon (rook) */void MyPolygon( Mat img ){ int lineType = 8; /** Create some points */ Point rook_points[1][20]; rook_points[0][0] = Point( w/4, 7*w/8 ); rook_points[0][1] = Point( 3*w/4, 7*w/8 ); rook_points[0][2] = Point( 3*w/4, 13*w/16 ); rook_points[0][3] = Point( 11*w/16, 13*w/16 ); rook_points[0][4] = Point( 19*w/32, 3*w/8 ); rook_points[0][5] = Point( 3*w/4, 3*w/8 ); rook_points[0][6] = Point( 3*w/4, w/8 ); rook_points[0][7] = Point( 26*w/40, w/8 ); rook_points[0][8] = Point( 26*w/40, w/4 ); rook_points[0][9] = Point( 22*w/40, w/4 ); rook_points[0][10] = Point( 22*w/40, w/8 ); rook_points[0][11] = Point( 18*w/40, w/8 ); rook_points[0][12] = Point( 18*w/40, w/4 ); rook_points[0][13] = Point( 14*w/40, w/4 ); rook_points[0][14] = Point( 14*w/40, w/8 ); rook_points[0][15] = Point( w/4, w/8 ); rook_points[0][16] = Point( w/4, 3*w/8 ); rook_points[0][17] = Point( 13*w/32, 3*w/8 ); rook_points[0][18] = Point( 5*w/16, 13*w/16 ); rook_points[0][19] = Point( w/4, 13*w/16 ); const Point* ppt[1] = { rook_points[0] }; int npt[] = { 20 }; fillPoly( img, ppt, npt, 1, Scalar( 255, 255, 255 ), lineType );}/** * @function MyLine * @brief Draw a simple line */void MyLine( Mat img, Point start, Point end ){ int thickness = 2; int lineType = 8; line( img, start, end, Scalar( 0, 0, 0 ), thickness, lineType );}结果:
0 0
- (14)Air Band OpenCV2.4.13_基础作图
- (11)Air Band OpenCV2.4.13_矩阵掩码操作
- (12)Air Band OpenCV2.4.13_将两幅图片叠加
- (16)Air Band OpenCV2.4.13_离散傅里叶变换
- (19)Air Band OpenCV2.4.13_平滑图像
- (20)Air Band OpenCV2.4.13_腐蚀和膨胀
- (21)Air Band OpenCV2.4.13_其他形态学变换
- (22)Air Band OpenCV2.4.13_图像金字塔
- (23)Air Band OpenCV2.4.13_基本阈值操作
- (24)Air Band OpenCV2.4.13_自定义线性滤波器
- (25)Air Band OpenCV2.4.13_为图像添加边界
- (32)Air Band OpenCV2.4.13_重映射
- (34)Air Band OpenCV2.4.13_直方图均衡化
- (35)Air Band OpenCV2.4.13_直方图计算
- (36)Air Band OpenCV2.4.13_直方图比较
- (37)Air Band OpenCV2.4.13_反向投影
- (38)Air Band OpenCV2.4.13_模板匹配
- (40)Air Band OpenCV2.4.13_凸包
- hdu1426 Sudoku Killer
- 445. Add Two Numbers II
- PIC单片机-PWM波
- 有关inputstream流只能读取一次的问题
- 2016HCTF giligili writeup
- (14)Air Band OpenCV2.4.13_基础作图
- 2017zctf misc300
- Java之GUI
- C++ string类 详细用法
- “空”的艺术-当数据为空时显示什么
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
- ubuntu下安装nfs服务器
- 中规模实现组合逻辑函数(两种)
- SQL Server 行列相互转换命令:PIVOT和UNPIVOT使用详解