色婷婷AV无码久久精品,久久天天躁狠狠躁夜夜97,羞羞麻豆国产精品1区2区3区,啪影院免费线观看视频,思思久久er99精品亚洲

常州機(jī)器視覺(jué)培訓(xùn)

常州上位機(jī)軟件開(kāi)發(fā)

常州工業(yè)機(jī)器人編程設(shè)計(jì)培訓(xùn)

常州PLC培訓(xùn)

常州PLC

常州PLC編程培訓(xùn)

常州電工培訓(xùn)

常州和訊plc培訓(xùn)中心歡迎您!
當(dāng)前位置:網(wǎng)站首頁(yè) > 新聞中心 新聞中心
opencv繪制一個(gè)模擬時(shí)鐘-常州上位機(jī)培訓(xùn),常州機(jī)器視覺(jué)培訓(xùn)
日期:2024-4-3 16:37:01人氣:  標(biāo)簽:常州上位機(jī)培訓(xùn) 常州機(jī)器視覺(jué)培訓(xùn)

算法背后的想法很簡(jiǎn)單:

 決定要在其中繪制模擬時(shí)鐘的窗口的大小。這里的窗口大小是 640 * 640。

因此這個(gè)窗口的中心是 (320,320)作為圓心畫(huà)一個(gè)圓(圓的大小應(yīng)該小于窗口的大。┈F(xiàn)在我們需要在圓的圓周上有時(shí)針和秒針的標(biāo)記 時(shí)針和秒針的坐標(biāo)可以通過(guò)使用圓參數(shù)方程得到:

image.png

由于中心的坐標(biāo)是 (Cx,Cy)因此該點(diǎn)的坐標(biāo)將是


x1=Cx+rCos(θ)


y1= Cy + rsin(θ)




因此,在獲得坐標(biāo)后,我們需要為分鐘和小時(shí)標(biāo)記畫(huà)一條線

對(duì)于時(shí)針的標(biāo)記:我們?nèi)⊥鈭A半徑為:315內(nèi)圈半徑為:275

對(duì)于分針的標(biāo)記:我們?nèi)⊥鈭A的半徑為:315內(nèi)圈為:275



注意:


由于 12 小時(shí)對(duì)應(yīng)于時(shí)針旋轉(zhuǎn) 360 度


因此,一小時(shí)分針應(yīng)旋轉(zhuǎn) 360/12=30 度


 因此角度,時(shí)針會(huì)變化 30 度

每旋轉(zhuǎn) 30 度,我們有 5 分鐘


  因此,每分鐘,分針應(yīng)旋轉(zhuǎn) 30/5=6  度      


 因此,分針的角度會(huì)變化 6 度

 180 度 = π 弧度 因此 θ 度= (θ*π/180) 弧度




接下來(lái)我們需要用系統(tǒng)時(shí)鐘更新我們的時(shí)針、分針和秒針。




代碼如下


#include <iostream>

#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc_c.h"

#include "opencv2/imgproc/imgproc.hpp"

#include <stdio.h>

#include <ctime>

#include <sys/timeb.h>

using namespace std;

using namespace cv;


int main()

{

    Mat clk(640, 640, CV_8UC3); //Mat to store clock image

    Mat back_up(640, 640, CV_8UC3); //Mat to store backup image


    Point cent(320, 320);

    Point perim(0, 0);

    int rad = 320;

    float sec_angle, min_angle, hour_angle;




    //Draw second markings

    int s1[60]image.png;

    for (int i = 0; i < 60; i++)

        for (int j = 0; j < 2; j++)

            if (j % 2 == 0)

                s1[i][j] = 320 + 295 * cos(6.0 * i * 3.14 / 180);

            else

                s1[i][j] = 320 + 295 * sin(6.0 * i * 3.14 / 180);


    int s2[60]image.png;

    for (int i = 0; i < 60; i++)

        for (int j = 0; j < 2; j++)

            if (j % 2 == 0)

                s2[i][j] = 320 + 315 * cos(6.0 * i * 3.14 / 180);

            else

                s2[i][j] = 320 + 315 * sin(6.0 * i * 3.14 / 180);


    for (int i = 0; i < 60; i++) {

        line(clk, Point(s1[i]image.png, s1[i]image.png), Point(s2[i]image.png, s2[i]image.png), Scalar(0, 255, 0, 0), 1.5, CV_AA, 0);

    }



    //Draw hour markings

    int h1image.pngimage.png;

    for (int i = 0; i < 12; i++)

        for (int j = 0; j < 2; j++)

            if (j % 2 == 0)

                h1[i][j] = 320 + 275 * cos(30.0 * i * 3.14 / 180);

            else

                h1[i][j] = 320 + 275 * sin(30.0 * i * 3.14 / 180);


    int h2image.pngimage.png;

    for (int i = 0; i < 12; i++)

        for (int j = 0; j < 2; j++)

            if (j % 2 == 0)

                h2[i][j] = 320 + 315 * cos(30.0 * i * 3.14 / 180);

            else

                h2[i][j] = 320 + 315 * sin(30.0 * i * 3.14 / 180);

    for (int i = 0; i < 12; i++) {

        line(clk, Point(h1[i]image.png, h1[i]image.png), Point(h2[i]image.png, h2[i]image.png), Scalar(0, 255, 0, 0), 4, CV_AA, 0);

    }


    circle(clk, cent, rad - 5, Scalar(0, 0, 255, 0), 4, CV_AA, 0); //Draw outercircle of clock

    circle(clk, cent, 1, Scalar(0, 255, 0, 0), 5, CV_AA, 0);        //Draw inner circle


    back_up = clk.clone();                                                  // Clone to backup image


    time_t rawtime;

    struct tm timeinfo;

    float second;

    float minute;

    float hour;

    float millisec;

    struct timeb tmb;



    while (1) {

        //Access system time and store it to a local variable

        ftime(&tmb);

        rawtime = tmb.time;



        localtime_s(&timeinfo,&rawtime);


        second = timeinfo.tm_sec;

        minute = timeinfo.tm_min;

        hour = timeinfo.tm_hour;

        millisec = tmb.millitm;



        second = second + millisec / 1000;

        sec_angle = (second * 6) + 270;                     //Convert second to angle


        minute = minute + second / 60;

        min_angle = minute * 6 + 270;                        //Convert minute to angle


        if (hour > 12)hour = hour - 12;

        hour_angle = (hour * 30) + (minute * .5) + 270;  //Convert hour to angle



        if (sec_angle > 360)sec_angle = sec_angle - 360;

        if (min_angle > 360)min_angle = min_angle - 360;

        if (hour_angle > 360)hour_angle = hour_angle - 360;


        //Find out the co-ordinates in the circle perimeter for second and draw the line from center

        perim.x = (int)(cent.x + (rad - 5) * cos(sec_angle * CV_PI / 180.0));

        perim.y = (int)(cent.y + (rad - 5) * sin(sec_angle * CV_PI / 180.0));

        line(clk, cent, perim, Scalar(0, 255, 255, 0), 1.5, CV_AA, 0);



        //Find out the co-ordinates on the circle perimeter for minute and draw the line from center

        perim.x = (int)(cent.x + (rad - 50) * cos(min_angle * CV_PI / 180.0));

        perim.y = (int)(cent.y + (rad - 50) * sin(min_angle * CV_PI / 180.0));

        line(clk, cent, perim, Scalar(0, 255, 255, 0), 4, CV_AA, 0);



        //Find out the co-ordinates on the circle perimeter for hour and draw the line from center

        perim.x = (int)(cent.x + (rad - 75) * cos(hour_angle * CV_PI / 180.0));

        perim.y = (int)(cent.y + (rad - 75) * sin(hour_angle * CV_PI / 180.0));

        line(clk, cent, perim, Scalar(0, 255, 255, 0), 8, CV_AA, 0);



        imshow("Clock", clk);  //Show result in a window

        clk.setTo(0);                // set clk image to zero for next drawing

        clk = back_up.clone();  // Clone the previously drawned markings from back-up image


        char c = waitKey(10);   // Wait for few millisecond and go back to loop.

        if (c == 27)break;

    }


    return 0;

}

效果如圖:

image.png

本文網(wǎng)址:
下一篇:沒(méi)有資料

相關(guān)信息:
版權(quán)所有 CopyRight 2006-2017 江蘇和訊自動(dòng)化設(shè)備有限公司 常州自動(dòng)化培訓(xùn)中心 電話:0519-85602926 地址:常州市新北區(qū)府琛商務(wù)廣場(chǎng)2號(hào)樓1409室
蘇ICP備14016686號(hào)-2 技術(shù)支持:常州山水網(wǎng)絡(luò)
本站關(guān)鍵詞:常州PLC培訓(xùn) 常州PLC編程培訓(xùn) 常州PLC編程 常州PLC培訓(xùn)班 網(wǎng)站地圖 網(wǎng)站標(biāo)簽
在線與我們?nèi)〉寐?lián)系
色婷婷AV无码久久精品,久久天天躁狠狠躁夜夜97,羞羞麻豆国产精品1区2区3区,啪影院免费线观看视频,思思久久er99精品亚洲