逆時針畫圓弧,原理:將360度分割成36份,分別標出每10度角度時的坐標點,然后將每個點連接起來。
創(chuàng)新互聯(lián)客戶idc服務中心,提供成都服務器托管、成都服務器、成都主機托管、成都雙線服務器等業(yè)務的一站式服務。通過各地的服務中心,我們向成都用戶提供優(yōu)質(zhì)廉價的產(chǎn)品以及開放、透明、穩(wěn)定、高性價比的服務,資深網(wǎng)絡(luò)工程師在機房提供7*24小時標準級技術(shù)保障。#include <iostream> #include <opencv2\core\core.hpp> #include <opencv2\opencv.hpp> #include <opencv2\highgui\highgui.hpp> #include <opencv2\contrib\contrib.hpp> #include <fstream> #include <windows.h> using namespace cv; using namespace std; // 圖像、圓心、開始點、結(jié)束點、線寬 void DrawArc(Mat *src, Point ArcCenter, Point StartPoint, Point EndPoint, int Fill) { if (Fill <= 0) return; vector<Point> Dots; double Angle1 = atan2((StartPoint.y - ArcCenter.y), (StartPoint.x - ArcCenter.x)); double Angle2 = atan2((EndPoint.y - ArcCenter.y), (EndPoint.x - ArcCenter.x)); double Angle = Angle1 - Angle2; Angle = Angle * 180.0 / CV_PI; if (Angle < 0) Angle = 360 + Angle; if (Angle == 0) Angle = 360; int brim = floor(Angle / 10); // 向下取整 Dots.push_back(StartPoint); for (int i = 0; i < brim; i++) { double dSinRot = sin(-(10 * (i + 1)) * CV_PI / 180); double dCosRot = cos(-(10 * (i + 1)) * CV_PI / 180); int x = ArcCenter.x + dCosRot * (StartPoint.x - ArcCenter.x) - dSinRot * (StartPoint.y - ArcCenter.y); int y = ArcCenter.y + dSinRot * (StartPoint.x - ArcCenter.x) + dCosRot * (StartPoint.y - ArcCenter.y); Dots.push_back(Point(x, y)); } Dots.push_back(EndPoint); RNG &rng = theRNG(); Scalar color = Scalar(rng.uniform(100, 255), rng.uniform(100, 255), rng.uniform(100, 255)); for (int i = 0; i < Dots.size() - 1; i++) { line(*src, Dots[i], Dots[i + 1], color, Fill); } Dots.clear(); } int main() { Mat Img = Mat::zeros(800, 800, CV_8UC3); int64 tim = getTickCount(); // 坐標零點 400,400 Point ZeroPoint = Point(400, 400); // 起始坐標 150,-100 Point StartPoint = Point(ZeroPoint.x +150, ZeroPoint.y - (-100)); // 結(jié)束坐標 -150,-100 Point EndPoint = Point(ZeroPoint.x - 150, ZeroPoint.y - (-100)); // 圓心相對起始點的坐標 -150,200 int I = StartPoint.x - 150; int J = StartPoint.y - (+200); Point Arc = Point(I, J); // 顯示圓心坐標 circle(Img, Arc, 5, Scalar(0, 0, 255), -1); // 顯示起始點坐標 circle(Img, StartPoint, 5, Scalar(255, 0, 0), -1); // 顯示結(jié)束點坐標 circle(Img, EndPoint, 5, Scalar(0, 255, 0), -1); // 圖像、圓心、開始點、結(jié)束點、線寬 DrawArc(&Img, Arc, StartPoint, EndPoint, 2); imshow("正多邊形", Img); tim = getTickCount() - tim; printf("處理耗時: %fms\n\n", tim * 1000 / getTickFrequency()); waitKey(0); return 0; }
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)建站aaarwkj.com,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
標題名稱:OpenCV畫任意圓弧曲線-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://aaarwkj.com/article42/dpishc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供動態(tài)網(wǎng)站、關(guān)鍵詞優(yōu)化、企業(yè)網(wǎng)站制作、ChatGPT、小程序開發(fā)、面包屑導航
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)