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函数制作的时钟模型的更多相关文章

  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. DNS递归查询与迭代查询

    注:一般TCP/IP的应用层或者OSI的会话.表示.应用层把数据称为数据或者信息,到了传输层把数据称为报文,到了最底层就是比特流了也就是字节流 DNS递归查询与迭代查询   基础知识 1.域名系统 2 ...

  2. 【python 3.6】笨办法取出列表中的字典的value

    #python 3.6 #!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'BH8ANK' x = {'RegionSet': [{' ...

  3. NO.2:自学python之路------变量类型、列表、字典

    引言 本周初步认识了库,并学习了Python中各种类型的变量和常用操作.并完成了较为完善的用户与商家购物界面设计. 正文 模块: Python有标准库和第三方库.第三方库需要安装才能使用.大量的库可以 ...

  4. [C++] Solve "Launch Failed. Binary not found." error on Eclipse

    This error is that the default lanch configuration is not being created for this project. To solve i ...

  5. 欢迎来怼—第二次Scrum会议

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华小组照片 二.开会信息 时间:2017/10/14 18:30~18:47,总计17min.地点:东北师范 ...

  6. python knn自我实践

    #得到分类数据和测试数据 import pymysql import struct from numpy import * a=['']*20 #存图像 分类数据 b=[[0]*76800]*20#存 ...

  7. HDU 5661 Claris and XOR 贪心

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

  8. python、Eclipse、pydev环境配置

    转载来源:http://www.cnblogs.com/Bonker/p/3584707.html 编辑器: Eclipse + pydev插件: 1. Eclipse是写JAVA的IDE, 这样就可 ...

  9. lintcode-419-罗马数字转整数

    419-罗马数字转整数 给定一个罗马数字,将其转换成整数. 返回的结果要求在1到3999的范围内. 说明 什么是 罗马数字? https://en.wikipedia.org/wiki/Roman_n ...

  10. 解决Max retries exceeded with url的问题

    requests.exceptions.ConnectionError: HTTPSConnectionPool(host='itunes.apple.com', port=443): Max ret ...