opencv函数制作的时钟模型
http://www.cnblogs.com/sytu/p/4192652.html
在秒针模型的基础上添加了分针和时针,并且添加了暂停控件和设置时间的功能。
- #include"cv.h"
- #include"highgui.h"
- int run = ;
- void Stop_Run_onclick(int event,int x,int y,int flags,void* param)
- {
- switch (event)
- {
- case CV_EVENT_LBUTTONDOWN:{
- if (x< && x> && y< && y>)
- {
- run = !run;
- }
- }
- default:
- break;
- }
- }
- void Drwan_button(IplImage* plane)
- {
- //画按钮
- cvRectangle(plane, cvPoint(, ), cvPoint(, ), cvScalar(, , ), );
- cvSetImageROI(plane, cvRect(, , , ));
- cvZero(plane);
- cvFloodFill(plane,cvPoint(,),cvScalarAll(),cvScalarAll());
- cvResetImageROI(plane);
- if (run)
- cvPutText(plane, "StopTime", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- else
- {
- cvPutText(plane, "RunTime", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- }
- }
- double PIZHI(int count)
- {
- return *(1.0*count / 60.0 * 3.1415926);
- }
- int main()
- {
- IplImage* Plane = cvCreateImage(cvSize(,),,);
- cvAddS(Plane,cvScalar(,,),Plane);
- cvCircle(Plane,cvPoint(,),,cvScalar(,,),);
- cvPutText(Plane,"",cvPoint(,),&cvFont(,),cvScalar(,,));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
- cvCircle(Plane,cvPoint(,),,cvScalarAll(),);
- cvNamedWindow("Clock");
- cvSetMouseCallback("Clock",Stop_Run_onclick,);
- Drwan_button(Plane);
- cvShowImage("Clock",Plane);
- IplImage* img = cvCreateImage(cvGetSize(Plane),,);
- double dangle = 0.1036;
- int r = ;
- int x = , y = ;//圆心
- int count_s = ;
- int count_m = ;
- int x1, x2;
- //for seconds
- double angle = ;
- int dx = ;
- int dy = ;
- //for minutes
- double angle_m = ;
- int mx = ;
- int my = ;
- //for hours
- double angle_h = ;
- int hx=, hy = ;
- int count_h = ;
- //设置时钟输入调节
- //angle;
- //angle_m;
- //angle_h;
- //count_m;
- //count_s;
- printf("\t\t\t选项\n\t\t\t从零点开始走针(1)\n\t\t\t从历史记录的时间走针(2)\n\t\t\t输入选项:");
- int judge;
- scanf("%d", &judge);
- if (judge == ){
- FILE *file = fopen("TimeRecord.dat", "r");
- fscanf(file, "%lf %lf %lf %d %d %d", &angle_h, &angle_m, &angle, &count_h, &count_m, &count_s);
- fclose(file);
- }
- system("cls");
- printf("按下ESC键可以退出!\n");
- printf("Enter键或者屏幕按键可以暂停钟表转动\n");
- printf("按下空格键可以设置时间:(输入格式为00:00:00)\n");
- while (true)
- {
- if (run){
- cvCopy(Plane, img);
- dy = r * cos(angle);
- dx = r * sin(angle);
- //for seconds
- my = r * cos(angle_m);
- mx = r * sin(angle_m);
- //for hours
- hx = r * sin(angle_h);
- hy = r * cos(angle_h);
- count_s++;
- angle=PIZHI(count_s);
- cvLine(img, cvPoint(x, y), cvPoint(x + hx / , x - hy / ), cvScalar(, , ), );
- cvLine(img, cvPoint(x, y), cvPoint(x + mx / 1.5, y - my / 1.5), cvScalar(, , ), );
- cvLine(img, cvPoint(x, y), cvPoint(x + dx, y - dy), cvScalar(, , ), );
- if (count_s == ||judge==)
- {
- if (judge!=)
- count_s = ;
- count_m++;
- angle = ;
- angle_m=PIZHI(count_m);
- if (count_m % == ||judge==){
- count_h++;
- angle_h = PIZHI(count_h);
- if (count_h == )count_h = ;
- }
- if (count_m == )count_m = ;
- judge = ;
- }
- }
- Drwan_button(img);
- cvShowImage("Clock", img);
- char ch = cvWaitKey();
- if (ch == )
- {
- FILE* write = fopen("TimeRecord.dat","w");
- fprintf(write, "%lf %lf %lf %d %d %d", angle_h, angle_m, angle, count_h, count_m, count_s);
- fclose(write);
- break;
- }
- else if (ch==)
- {
- run = !run;
- }
- else if (ch == )
- {
- scanf("%d:%d:%d",&count_h,&count_m,&count_s);
- count_h=count_h * + 1.0*count_m / 12.0;
- judge = ;
- }
- }
- cvWaitKey();
- return ;
- }
做着挺好玩的,就当练练手吧。
opencv函数制作的时钟模型的更多相关文章
- opencv函数制作的秒针模型
曾经做过,没想到这次再次写这篇代码却用了这么久的时间.这回我要记住他. #include"cv.h" #include"highgui.h" int main( ...
- 使用jQuery和CSS3制作数字时钟(jQuery篇) 附源码下载
HTML 和上一篇文章:使用jQuery和CSS3制作数字时钟(CSS3篇)一样的HTML结构,只是多了个>date用来展示日期和星期的. <div id="clock" ...
- csharp通过dll调用opencv函数,图片作为参数
[blog 项目实战派]csharp通过dll调用opencv函数,图片作为参数 一直想做着方面的研究,但是因为这个方面的知识过于小众,也是由于自己找资料的能力比较弱,知道今天才找 ...
- matlab调用opencv函数的配置
环境: VS2010 活动解决方案平台x64 WIN 8.1 Opencv 2.4.3 Matlab 2012a 1. 首先保证vs2010能正确调用opencv函数, 2. Matlab中选择编 ...
- [TPYBoard-Micropython之会python就能做硬件 3] 制作电子时钟
转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.TPYboard V102板 一块 2.DS3231 ...
- OpenCv函数学习(一)
Intel Image Processing Library (IPL) typedef struct _IplImage { int nSize; /* IplImage大小 */ int ID; ...
- 一些常用的opencv函数
分配图像空间: IplImage* cvCreateImage(CvSize size, int depth, int channels); size: cvSize(width,hei ...
- Excel中用REPT函数制作图表
本文从以下七个方面,阐述在Excel中用REPT函数制作图表: 一. 图形效果展示 二. REPT语法解释 三. REPT制作条形图 四. REPT制作漏斗图 五. REPT制作蝴蝶图 六. REPT ...
- 常用的OpenCV函数速查
常用的OpenCV函数速查 1.cvLoadImage:将图像文件加载至内存: 2.cvNamedWindow:在屏幕上创建一个窗口: 3.cvShowImage:在一个已创建好的窗口中显示图像: 4 ...
随机推荐
- PHP性能优化 -理论篇
什么情况下,遇到了PHP性能问题? 1 PHP语法使用的不恰当 2 使用PHP语言做不了它不擅长做的事 3 用php语言连接的服务不给力 4 PHP自身的短板 5 我也不 ...
- CSS 实用实例
背景颜色 1. 颜色背景 <style type="text/css">body { font-size: 16px;">h1 { font-size: ...
- “Hello World!”团队——Final发布用户使用报告
博客内容: 1.用户体验报告表 2.用户评论截图 3.总结 一.用户体验报告表 用户使用报告 用户类别 用户姓名(化名) 性别 用户职业 使用频次 用户评论 新增用户 小小静 女 中学信息技术老师 8 ...
- flask验证登录学习过程(1)---准备
对应flask的接口开发,目前自己可以熟练的进行.但是深入到更基础的,从注册到验证登录的过程一直不是特别清楚. 趁着年度不是特别忙的时候,特意去学习加强一下.把这个过程记录在此处. 首先是规划一个项目 ...
- HDU 5617 Jam's maze dp+滚动数组
题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5617 bc(中文):http://bestcoder.hdu.edu.cn/contest ...
- 配置resin web方式部署项目
写在前面,推荐下载resin4.0.47版本.其它版本没有测试 最近打算做一个小项目,然后容器选用了resin.想通过web提交war文件的方式 进行部署,更新代码也方便. 试了resin最新的版本( ...
- Scrum冲刺博客汇总
第一篇 Scrum冲刺博客 http://www.cnblogs.com/LZTZ/p/8886296.html 第二篇 Scrum冲刺博客 http://www.cnblogs.com/LZTZ/p ...
- cli 中php的配置和phpinfo不一样
这是因为加载的php.ini的路径不一样 可以通过查看 php -i | grep php.ini 来确定两个加载的配置路径是一样的 win中没有grep的命令,可以把php -i 的内容重定向输出到 ...
- Linux学习笔记3
touch filename 创建一个不存在的文件,或者修改文件的时间戳. touch log.txt whereis name 定位一个文件. whereis php.ini whereis.loc ...
- sharepoint content type publishing
1. Create 1 Project Team sites (Site1) on SharePoint(可以用普通site)2. Go to http://<PCName>:8080/_ ...