基础学习笔记之opencv:基本绘图.doc_第1页
基础学习笔记之opencv:基本绘图.doc_第2页
基础学习笔记之opencv:基本绘图.doc_第3页
基础学习笔记之opencv:基本绘图.doc_第4页
基础学习笔记之opencv:基本绘图.doc_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

基础学习笔记之opencv(13):基本绘图本文主要讲讲怎样用opencv画一些基本图形,这些图形包括,直线,圆,椭圆,多边形等。参考资料为opencv自带tutiol及其code。开发环境:ubuntu12.04+Qt4.8.2+QtCreator2.5+opencv2.4.2实验功能:1.单击Drawing1按钮,将会画出atom图形,并且可以看出该图形成的过程,共分5个步骤画,每画完1个部分会自动停留1s,以便观察,然后画下一个部分,直至完成atom图形。2.单击Drawing2按钮,将会画出rook图形,并且可以看出该图形成的过程,共分3个步骤画,每画完1个部分会自动停留1s,以便观察,然后画下一个部分,直至完成atom图形。3.单击close按钮,退出程序。实验说明:1. QtextEdit除了用append()函数显示图片外,还可以用insertHtml()函数和setPlainText()来显示,用法类似,其中insertHtml()可以用来显示图片和有格式的文字,而setPlainText()只能用来显示无格式的文字。2.为什么TextBrowser下的append()函数2个连在一起使用时,只有当最后一个append函数运行完后才显示出append的内容呢?比如说,ui-textBrowser-append( “first” );usleep( 1000000 );/延时1sui-textBrowser-append( “second” );usleep( 1000000 );ui-textBrowser-append( “third” );实际运行到这几句代码时,并不是显示完first,延时1s后显示second,再延时1s后显示third. 而是直接延时2秒,first,second,third同时显示呢?而把程序改成在终端输出字符串,用的usleep函数,其结果却正常,能满足我们预先设定的了。即改为下面代码时:coutfirstendl;usleep( 1000000 );/延时1scoutsecondendl;usleep( 1000000 );countthirdendl;其原因在主线程GUI中不宜采用sleep()等函数,否则会出现意想不到的结果。如果需要延时,#include 后,可以用下面的代码(比如说延时1s):QElapsedTimer t;t.start();while(t.elapsed()1000)QcoreApplication:processEvents();3.fillPoly函数的第2个参数是指1个指向Point的双指针,因为该函数可以同时填充多个多边形。第3个参数为指向整型的指针,表示每个多边形中顶点的个数。实验结果:画atom图过程之一及其结果:画rook图过程之一及其结果:实验主要部分代码及注释(附录有工程code下载链接):#include mainwindow.h#include ui_mainwindow.h/#include /#include #include #include using namespace std;MainWindow:MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui:MainWindow) ui-setupUi(this); ui-textBrowser-setFixedWidth( W ); ui-textBrowser-setFixedHeight( W );MainWindow:MainWindow() delete ui;void MainWindow:on_closeButton_clicked() close();void MainWindow:on_drawing1Button_clicked() /*画图1,资料中称该图为atom*/ img = Mat:zeros( W, W, CV_8UC3 ); imwrite( ./drawing/drawing.jpg, img ); ui-textBrowser-insertHtml( ); /*下面几句为在Qt中常用的延时函数,这里为延时1s,注意主线程中不要采用sleep()等函数 否则会出现意想不到的结果*/ QElapsedTimer t; t.start(); while(t.elapsed()textBrowser-clear(); my_ellipse( img, 0 ); imwrite ( ./drawing/drawing1.jpg, img ); ui-textBrowser-append( ); t.start(); while(t.elapsed()textBrowser-clear(); my_ellipse( img ,90 ); imwrite ( ./drawing/drawing2.jpg, img ); ui-textBrowser-append( ); t.start(); while(t.elapsed()textBrowser-clear(); my_ellipse( img, 45 ); imwrite ( ./drawing/drawing3.jpg, img ); ui-textBrowser-append( ); t.start(); while(t.elapsed()textBrowser-clear(); my_ellipse( img, 135 ); imwrite ( ./drawing/drawing3.jpg, img ); ui-textBrowser-append( ); t.start(); while(t.elapsed()textBrowser-clear(); my_filled_circle( img, Point(W/2, W/2) ); imwrite ( ./drawing/drawing3.jpg, img ); ui-textBrowser-append( ); t.start(); while(t.elapsed()textBrowser-insertHtml( ); QElapsedTimer t; t.start(); while(t.elapsed()textBrowser-clear(); my_polygon( img ); imwrite ( ./drawing/drawing2.jpg, img ); ui-textBrowser-append( ); t.start(); while(t.elapsed()textBrowser-clear(); rectangle( img, Rect( Point(0, 7*W/8), Point(W, W) ), Scalar(0, 0, 255), -1, 8); imwrite ( ./drawing/drawing2.jpg, img ); ui-textBrowser-append( ); t.start(); while(t.elapsed()textBrowser-clear(); my_line( img, Point(0, 15*W/16), Point( W, 15*W/16) ); my_line( img, Point(W/4, W/8), Point(W/4, W) ); my_line( img, Point(W/2, 7*W/8), Point(W/2, W) ); my_line( img, Point(3*W/4, W/8), Point(3*W/4, W) ); imwrite ( ./drawing/drawing2.jpg, img ); ui-textBrowser-append( ); t.start(); while(t.elapsed()1000) QCoreApplication:processEvents();void MainWindow:my_ellipse( Mat& img, float angle ) cv:ellipse( img, Point(W/2, W/2), Size(3*W/8, W/8), angle, 0, 360, Scalar(0, 255, 0), 2, 8 );void MainWindow:my_filled_circle( Mat& img, Point center ) cv:circle( img, center, W/8, Scalar(0, 0, 255), -1, 8 );void MainWindow:my_polygon( Mat& img ) int ncontours = 1; Point rook_points120; rook_points00 = Point( W/4.0, 7*W/8.0 ); rook_points01 = Point( 3*W/4.0, 7*W/8.0 ); rook_points02 = Point( 3*W/4.0, 13*W/16.0 ); rook_points03 = Point( 11*W/16.0, 13*W/16.0 ); rook_points04 = Point( 19*W/32.0, 3*W/8.0 ); rook_points05 = Point( 3*W/4.0, 3*W/8.0 ); rook_points06 = Point( 3*W/4.0, W/8.0 ); rook_points07 = Point( 26*W/40.0, W/8.0 ); rook_points08 = Point( 26*W/40.0, W/4.0 ); rook_points09 = Point( 22*W/40.0, W/4.0 ); rook_points010 = Point( 22*W/40.0, W/8.0 ); rook_points011 = Point( 18*W/40.0, W/8.0 ); rook_points012 = Point( 18*W/40.0, W/4.0 ); rook_points013 = Point( 14*W/40.0, W/4.0 ); rook_points014 = Point( 14*W/40.0, W/8.0 ); rook_points015 = Point( W/4.0, W/8.0 ); rook_points016 = Point( W/4.0, 3*W/8.0 ); rook_points017 = Point( 13*W/32.0, 3*W/8.0 ); rook_points018 = Point( 5*W/16.0, 13*W/16.0 ); rook_points019 = Point( W/4.0, 13*W/16.0) ; const Point *pts1 = rook_points0 ; / const Point *pts = rook_points;/这样定义是不行的,因为rook_points是个常量的二阶指针 int npts1 = 20 ; /用指定颜色填充指定闭合的多边形。 fillPoly( img, pts, npts, ncontours, Scalar

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论