下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、在 mfc 中我们经常会画线、矩形、椭圆、多边形等几何结构,opencv 为我们供应了已经封装好的函数来实现该功能,而且简洁便利。下面供应一下例子,是 opencv 安装以后自带的小程序,学习完现在的程序你可以学会以下学问:(1)生成随机数,使用 rng 类(2) 画线(3)画矩形(4)画椭圆(5)画圆(6)输出文字、文本(7)假如不生疏 opencv 的还能学会 point 结构体的使用,scalar 结构使用。具体可以看下面的小例子。在vs2010 下运行一下就会明白了!#include “stdafx.h“#include “opencv2/core/core.hpp“ #include
2、 “opencv2/highgui/highgui.hpp“ #include <stdio.h>using namespace cv; void help()printf(“nthis program demonstrates opencv drawing and text output functions.n“ “usage:n“ ./drawingn“);static scalar randomcolor(rng& rng)int icolor = (unsigned)rng;return scalar(icolor&255, (icolor>>8
3、)&255, (icolor>>16)&255);int main()help();char wndname = “drawing demo“; const int number = 100;const int delay = 5;int linetype = cv_aa; / change it to 8 to see non-antialiased graphics int i, width = 1000, height = 700;int x1 = -width/2, x2 = width*3/2, y1 = -height/2, y2 = height*3/
4、2; rng rng(0xffffffff);mat image = mat:zeros(height, width, cv_8uc3); imshow(wndname, image);waitkey(delay);for (i = 0; i < number; i+)point pt1, pt2;pt1.x = rng.uniform(x1, x2); pt1.y = rng.uniform(y1, y2); pt2.x = rng.uniform(x1, x2); pt2.y = rng.uniform(y1, y2);line( image, pt1, pt2, randomcol
5、or(rng), rng.uniform(1,10), linetype ); imshow(wndname, image);if(waitkey(delay) >= 0)return 0;for (i = 0; i < number; i+)point pt1, pt2;pt1.x = rng.uniform(x1, x2); pt1.y = rng.uniform(y1, y2); pt2.x = rng.uniform(x1, x2); pt2.y = rng.uniform(y1, y2);int thickness = rng.uniform(-3, 10);rectan
6、gle( image, pt1, pt2, randomcolor(rng), max(thickness, -1), linetype ); imshow(wndname, image);if(waitkey(delay) >= 0)return 0;for (i = 0; i < number; i+)point center;center.x = rng.uniform(x1, x2); center.y = rng.uniform(y1, y2); size axes;axes.width = rng.uniform(0, 200); axes.height = rng.u
7、niform(0, 200); double angle = rng.uniform(0, 180);ellipse( image, center, axes, angle, angle - 100, angle + 200, randomcolor(rng), rng.uniform(-1,9), linetype ); imshow(wndname, image);if(waitkey(delay) >= 0)return 0;for (i = 0; i< number; i+)point pt23;pt00.x = rng.uniform(x1, x2);pt00.y = r
8、ng.uniform(y1, y2);pt01.x = rng.uniform(x1, x2);pt01.y = rng.uniform(y1, y2);pt02.x = rng.uniform(x1, x2);pt02.y = rng.uniform(y1, y2);pt10.x = rng.uniform(x1, x2);pt10.y = rng.uniform(y1, y2);pt11.x = rng.uniform(x1, x2);pt11.y = rng.uniform(y1, y2);pt12.x = rng.uniform(x1, x2);pt12.y = rng.uniform
9、(y1, y2);const point* ppt2 = pt0, pt1; int npt = 3, 3;polylines(image, ppt, npt, 2, true, randomcolor(rng), rng.uniform(1,10), linetype); imshow(wndname, image);if(waitkey(delay) >= 0)return 0;for (i = 0; i< number; i+)point pt23;pt00.x = rng.uniform(x1, x2);pt00.y = rng.uniform(y1, y2);pt01.x
10、 = rng.uniform(x1, x2);pt01.y = rng.uniform(y1, y2);pt02.x = rng.uniform(x1, x2);pt02.y = rng.uniform(y1, y2);pt10.x = rng.uniform(x1, x2);pt10.y = rng.uniform(y1, y2);pt11.x = rng.uniform(x1, x2);pt11.y = rng.uniform(y1, y2);pt12.x = rng.uniform(x1, x2);pt12.y = rng.uniform(y1, y2);const point* ppt
11、2 = pt0, pt1; int npt = 3, 3;fillpoly(image, ppt, npt, 2, randomcolor(rng), linetype); imshow(wndname, image);if(waitkey(delay) >= 0)return 0;for (i = 0; i < number; i+)point center;center.x = rng.uniform(x1, x2); center.y = rng.uniform(y1, y2);circle(image, center, rng.uniform(0, 300), random
12、color(rng), rng.uniform(-1, 9), linetype);imshow(wndname, image); if(waitkey(delay) >= 0)return 0;for (i = 1; i < number; i+)point org;org.x = rng.uniform(x1, x2); org.y = rng.uniform(y1, y2);puttext(image, “testing text rendering“, org, rng.uniform(0,8), rng.uniform(0,100)*0.05+0.1, randomcolor(rng), rng.uniform(1, 10), linetype); imshow(wndname, image);if(waitkey(delay) >= 0)return 0;size textsize = gettextsize(“opencv forever!“, cv_font_hershey_complex, 3, 5, 0);point org(width - textsize.width)/2, (height - textsize.height)/2); mat image2;for( i = 0; i < 255; i += 2 )image2
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 移动媒体艺术就业方向
- 2026湖南郴州市国控健康养老服务有限公司招聘6人笔试备考试题及答案解析
- 农药中毒患者的吸氧护理
- 2026北京市农林科学院高层次人才引进53人考试参考题库及答案解析
- 2026年调兵山市消防救援局公开补充招录政府专职消防队员7人笔试备考题库及答案解析
- 2026广东旅控集团财务管理部(资金结算中心)部长等岗位招聘2人考试备考试题及答案解析
- 2026广西崇左天等县住房和城乡建设局招聘编外工作人员2人笔试备考试题及答案解析
- 2025年江苏农林职业技术学院单招职业适应性测试题库及答案解析
- 职业规划师行业指南
- 2026年中国科大附中高新中学教师招聘考试备考题库及答案解析
- 加油站防恐安全培训
- 酒店线上推广方案
- 感受生活中的法律完整版
- Micro Shield程序初级应用指南
- GB/T 21837-2023铁磁性钢丝绳电磁检测方法
- 苏州山塘街区
- 职业卫生法律法规职业卫生法律法规
- 船体设计师个人简历模板
- 超声心动检查技术 心脏各瓣膜频谱多普勒的正常波形
- 2023学年完整公开课版《元宵节》
- 药物过敏急救处理
评论
0/150
提交评论