轮廓3
2016-03-24 10:12
218 查看
#include "cv.h" #include "cxcore.h" #include "highgui.h" #include <math.h> #define w 500 int levels = 3; CvSeq* contours = 0; void on_trackbar(int pos) { IplImage* cnt_img = cvCreateImage( cvSize(w,w), 8, 3 ); CvSeq* _contours = contours; int _levels = levels - 3; // if( _levels <= 0 ) // get to the nearest face to make it look more funny // _contours = _contours->h_next->h_next->h_next->h_next->h_next; cvZero( cnt_img ); cvDrawContours( cnt_img, _contours, CV_RGB(255,0,0), CV_RGB(0,255,0), _levels, 3, CV_AA, cvPoint(0,0) ); cvShowImage( "contours", cnt_img ); cvReleaseImage( &cnt_img ); } int main( int argc, char** argv ) { int i, j; CvMemStorage* storage = cvCreateMemStorage(0); IplImage* img = cvCreateImage( cvSize(w,w), 8, 1 ); cvZero( img ); for( i=0; i < 6; i++ ) { int dx = (i%2)*250 - 30; int dy = (i/2)*150; CvScalar white = cvRealScalar(255); CvScalar black = cvRealScalar(0); if( i == 0 ) { for( j = 0; j <= 10 ;j++ ) { double angle = (j+5)*CV_PI/21;//弧度制中1度所对应的值 cvLine(img, cvPoint(cvRound(dx+100+j*10-80*cos(angle)), cvRound(dy+100-90*sin(angle))), cvPoint(cvRound(dx+100+j*10-30*cos(angle)), cvRound(dy+100-30*sin(angle))), white, 1, 8, 0); } } cvEllipse( img, cvPoint(dx+150, dy+100), cvSize(100,70), 0, 0, 360, white, -1, 8, 0 ); cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(30,20), 0, 0, 360, black, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(30,20), 0, 0, 360, black, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(15,15), 0, 0, 360, white, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(15,15), 0, 0, 360, white, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+115, dy+70), cvSize(5,5), 0, 0, 360, black, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+185, dy+70), cvSize(5,5), 0, 0, 360, black, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+150, dy+100), cvSize(10,5), 0, 0, 360, black, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+150, dy+150), cvSize(40,10), 0, 0, 360, black, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+27, dy+100), cvSize(20,35), 0, 0, 360, white, -1, 8, 0 ); // cvEllipse( img, cvPoint(dx+273, dy+100), cvSize(20,35), 0, 0, 360, white, -1, 8, 0 ); } cvNamedWindow( "image", 1 ); cvShowImage( "image", img ); cvFindContours( img, storage, &contours, sizeof(CvContour), CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0) ); // comment this out if you do not want approximation contours = cvApproxPoly( contours, sizeof(CvContour), storage, CV_POLY_APPROX_DP, 3, 1 ); cvNamedWindow( "contours", 1 ); cvCreateTrackbar( "levels+3", "contours", &levels, 7, on_trackbar ); on_trackbar(0); cvWaitKey(0); cvReleaseMemStorage( &storage ); cvReleaseImage( &img ); return 0; }
相关文章推荐
- 抽象类
- phpredis中文手册——《redis中文手册》 php版
- FFMPEG之TimeBase成员理解
- 使用yy_modelSetWithDictionary 遇到key是系统关键字的更换
- symfony学习笔记-bundle1
- HDU 1429 胜利大逃亡(续) (BFS+二进制)
- android学习——SP方法实现用户登录
- Sqlite SN
- 正则表达式(参考java编程思想)
- Java之类的封装,继承,多态
- windows下流媒体nginx-rmtp-module服务器搭建
- high availability numbers
- LeetCode 66 Plus One
- IP地址的三种表示格式及在Socket编程中的应用
- 一步一步实现一个简单的OS(任务切换)
- JavaScript合并两个Json对象
- NSData 与 NSString 的转化
- Specified VM install not found: type Standard VM, name jdk1.6.0_05
- Matlab中有15种基本数据类型
- 如何验证Apusic集群搭建成功