http://www.cnblogs.com/sytu/p/4192652.html

在秒针模型的基础上添加了分针和时针,并且添加了暂停控件和设置时间的功能。

  1. #include"cv.h"
  2. #include"highgui.h"
  3. int run = ;
  4. void Stop_Run_onclick(int event,int x,int y,int flags,void* param)
  5. {
  6. switch (event)
  7. {
  8. case CV_EVENT_LBUTTONDOWN:{
  9. if (x< && x> && y< && y>)
  10. {
  11. run = !run;
  12. }
  13. }
  14. default:
  15. break;
  16. }
  17. }
  18. void Drwan_button(IplImage* plane)
  19. {
  20. //画按钮
  21. cvRectangle(plane, cvPoint(, ), cvPoint(, ), cvScalar(, , ), );
  22. cvSetImageROI(plane, cvRect(, , , ));
  23. cvZero(plane);
  24. cvFloodFill(plane,cvPoint(,),cvScalarAll(),cvScalarAll());
  25. cvResetImageROI(plane);
  26. if (run)
  27. cvPutText(plane, "StopTime", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  28. else
  29. {
  30. cvPutText(plane, "RunTime", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  31. }
  32. }
  33. double PIZHI(int count)
  34. {
  35. return *(1.0*count / 60.0 * 3.1415926);
  36. }
  37. int main()
  38. {
  39. IplImage* Plane = cvCreateImage(cvSize(,),,);
  40. cvAddS(Plane,cvScalar(,,),Plane);
  41. cvCircle(Plane,cvPoint(,),,cvScalar(,,),);
  42. cvPutText(Plane,"",cvPoint(,),&cvFont(,),cvScalar(,,));
  43. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  44. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  45. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  46. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  47. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  48. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  49.  
  50. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  51. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  52. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  53. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  54. cvPutText(Plane, "", cvPoint(, ), &cvFont(, ), cvScalar(, , ));
  55. cvCircle(Plane,cvPoint(,),,cvScalarAll(),);
  56. cvNamedWindow("Clock");
  57. cvSetMouseCallback("Clock",Stop_Run_onclick,);
  58. Drwan_button(Plane);
  59. cvShowImage("Clock",Plane);
  60. IplImage* img = cvCreateImage(cvGetSize(Plane),,);
  61. double dangle = 0.1036;
  62. int r = ;
  63. int x = , y = ;//圆心
  64. int count_s = ;
  65. int count_m = ;
  66. int x1, x2;
  67. //for seconds
  68. double angle = ;
  69. int dx = ;
  70. int dy = ;
  71. //for minutes
  72. double angle_m = ;
  73. int mx = ;
  74. int my = ;
  75. //for hours
  76. double angle_h = ;
  77. int hx=, hy = ;
  78. int count_h = ;
  79. //设置时钟输入调节
  80. //angle;
  81. //angle_m;
  82. //angle_h;
  83. //count_m;
  84. //count_s;
  85. printf("\t\t\t选项\n\t\t\t从零点开始走针(1)\n\t\t\t从历史记录的时间走针(2)\n\t\t\t输入选项:");
  86. int judge;
  87. scanf("%d", &judge);
  88. if (judge == ){
  89. FILE *file = fopen("TimeRecord.dat", "r");
  90. fscanf(file, "%lf %lf %lf %d %d %d", &angle_h, &angle_m, &angle, &count_h, &count_m, &count_s);
  91. fclose(file);
  92. }
  93. system("cls");
  94. printf("按下ESC键可以退出!\n");
  95. printf("Enter键或者屏幕按键可以暂停钟表转动\n");
  96. printf("按下空格键可以设置时间:(输入格式为00:00:00)\n");
  97.  
  98. while (true)
  99. {
  100. if (run){
  101. cvCopy(Plane, img);
  102. dy = r * cos(angle);
  103. dx = r * sin(angle);
  104. //for seconds
  105. my = r * cos(angle_m);
  106. mx = r * sin(angle_m);
  107. //for hours
  108. hx = r * sin(angle_h);
  109. hy = r * cos(angle_h);
  110. count_s++;
  111. angle=PIZHI(count_s);
  112. cvLine(img, cvPoint(x, y), cvPoint(x + hx / , x - hy / ), cvScalar(, , ), );
  113. cvLine(img, cvPoint(x, y), cvPoint(x + mx / 1.5, y - my / 1.5), cvScalar(, , ), );
  114. cvLine(img, cvPoint(x, y), cvPoint(x + dx, y - dy), cvScalar(, , ), );
  115.  
  116. if (count_s == ||judge==)
  117. {
  118. if (judge!=)
  119. count_s = ;
  120. count_m++;
  121. angle = ;
  122. angle_m=PIZHI(count_m);
  123. if (count_m % == ||judge==){
  124. count_h++;
  125. angle_h = PIZHI(count_h);
  126. if (count_h == )count_h = ;
  127. }
  128. if (count_m == )count_m = ;
  129. judge = ;
  130. }
  131. }
  132. Drwan_button(img);
  133. cvShowImage("Clock", img);
  134.  
  135. char ch = cvWaitKey();
  136. if (ch == )
  137. {
  138. FILE* write = fopen("TimeRecord.dat","w");
  139. fprintf(write, "%lf %lf %lf %d %d %d", angle_h, angle_m, angle, count_h, count_m, count_s);
  140. fclose(write);
  141. break;
  142. }
  143. else if (ch==)
  144. {
  145. run = !run;
  146. }
  147. else if (ch == )
  148. {
  149. scanf("%d:%d:%d",&count_h,&count_m,&count_s);
  150. count_h=count_h * + 1.0*count_m / 12.0;
  151. judge = ;
  152. }
  153. }
  154. cvWaitKey();
  155. return ;
  156. }

做着挺好玩的,就当练练手吧。

opencv函数制作的时钟模型的更多相关文章

  1. opencv函数制作的秒针模型

    曾经做过,没想到这次再次写这篇代码却用了这么久的时间.这回我要记住他. #include"cv.h" #include"highgui.h" int main( ...

  2. 使用jQuery和CSS3制作数字时钟(jQuery篇) 附源码下载

    HTML 和上一篇文章:使用jQuery和CSS3制作数字时钟(CSS3篇)一样的HTML结构,只是多了个>date用来展示日期和星期的. <div id="clock" ...

  3. csharp通过dll调用opencv函数,图片作为参数

    [blog 项目实战派]csharp通过dll调用opencv函数,图片作为参数          ​一直想做着方面的研究,但是因为这个方面的知识过于小众,也是由于自己找资料的能力比较弱,知道今天才找 ...

  4. matlab调用opencv函数的配置

    环境: VS2010 活动解决方案平台x64 WIN 8.1 Opencv 2.4.3 Matlab 2012a 1.  首先保证vs2010能正确调用opencv函数, 2.  Matlab中选择编 ...

  5. [TPYBoard-Micropython之会python就能做硬件 3] 制作电子时钟

    转载请注明:@小五义 http://www.cnblogs.com/xiaowuyi 欢迎加入讨论群 64770604 一.本次实验所需器材 1.TPYboard V102板  一块 2.DS3231 ...

  6. OpenCv函数学习(一)

    Intel Image Processing Library (IPL) typedef struct _IplImage { int nSize; /* IplImage大小 */ int ID; ...

  7. 一些常用的opencv函数

    分配图像空间: IplImage* cvCreateImage(CvSize size, int depth, int channels);       size:  cvSize(width,hei ...

  8. Excel中用REPT函数制作图表

    本文从以下七个方面,阐述在Excel中用REPT函数制作图表: 一. 图形效果展示 二. REPT语法解释 三. REPT制作条形图 四. REPT制作漏斗图 五. REPT制作蝴蝶图 六. REPT ...

  9. 常用的OpenCV函数速查

    常用的OpenCV函数速查 1.cvLoadImage:将图像文件加载至内存: 2.cvNamedWindow:在屏幕上创建一个窗口: 3.cvShowImage:在一个已创建好的窗口中显示图像: 4 ...

随机推荐

  1. PHP性能优化 -理论篇

    什么情况下,遇到了PHP性能问题?    1 PHP语法使用的不恰当    2 使用PHP语言做不了它不擅长做的事    3 用php语言连接的服务不给力    4 PHP自身的短板    5 我也不 ...

  2. CSS 实用实例

    背景颜色 1. 颜色背景 <style type="text/css">body { font-size: 16px;">h1 { font-size: ...

  3. “Hello World!”团队——Final发布用户使用报告

    博客内容: 1.用户体验报告表 2.用户评论截图 3.总结 一.用户体验报告表 用户使用报告 用户类别 用户姓名(化名) 性别 用户职业 使用频次 用户评论 新增用户 小小静 女 中学信息技术老师 8 ...

  4. flask验证登录学习过程(1)---准备

    对应flask的接口开发,目前自己可以熟练的进行.但是深入到更基础的,从注册到验证登录的过程一直不是特别清楚. 趁着年度不是特别忙的时候,特意去学习加强一下.把这个过程记录在此处. 首先是规划一个项目 ...

  5. HDU 5617 Jam's maze dp+滚动数组

    题目链接: hdu: http://acm.hdu.edu.cn/showproblem.php?pid=5617 bc(中文):http://bestcoder.hdu.edu.cn/contest ...

  6. 配置resin web方式部署项目

    写在前面,推荐下载resin4.0.47版本.其它版本没有测试 最近打算做一个小项目,然后容器选用了resin.想通过web提交war文件的方式 进行部署,更新代码也方便. 试了resin最新的版本( ...

  7. Scrum冲刺博客汇总

    第一篇 Scrum冲刺博客 http://www.cnblogs.com/LZTZ/p/8886296.html 第二篇 Scrum冲刺博客 http://www.cnblogs.com/LZTZ/p ...

  8. cli 中php的配置和phpinfo不一样

    这是因为加载的php.ini的路径不一样 可以通过查看 php -i | grep php.ini 来确定两个加载的配置路径是一样的 win中没有grep的命令,可以把php -i 的内容重定向输出到 ...

  9. Linux学习笔记3

    touch filename 创建一个不存在的文件,或者修改文件的时间戳. touch log.txt whereis name 定位一个文件. whereis php.ini whereis.loc ...

  10. sharepoint content type publishing

    1. Create 1 Project Team sites (Site1) on SharePoint(可以用普通site)2. Go to http://<PCName>:8080/_ ...