欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網!

C語言

當前位置:主頁 > 軟件編程 > C語言 >

OpenCV繪制正多邊形的方法

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

OpenCV 繪制正多邊形的具體代碼,供大家參考,具體內容如下

#include <iostream> 
#include <opencv2\core\core.hpp>
#include <opencv2\opencv.hpp> 
#include <opencv2\highgui\highgui.hpp> 
#include <opencv2\contrib\contrib.hpp> 
 
#include <fstream> 
 
using namespace cv;
using namespace std;
 
void DeleteRepetition(vector<Point> &Data)
{
 vector<Point>::iterator it, it1;
 for (it = ++Data.begin(); it != Data.end();) {
 it1 = find(Data.begin(), it, *it);
 if (it1 != it) it = Data.erase(it);
 else it++;
 }
}
 
void Patterns(Mat *src, vector<Point> Dots, int fill)
{
 DeleteRepetition(Dots);
 if (fill == -1)
 {
 Point *ImgDot = new Point(Dots.size());
 for (int i = 0; i < Dots.size(); i++) {
 ImgDot[i] = Dots[i];
 }
 const Point* ppt = ImgDot;
 int npt = Dots.size();
 RNG &rng = theRNG();
 Scalar color = Scalar(rng.uniform(100, 255), rng.uniform(100, 255), rng.uniform(100, 255));
 cv::fillPoly(*src, &ppt, &npt, 1, color);
 }
 else
 {
 Dots.push_back(Dots[0]);
 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);
 }
 }
}
 
// https://www.w3cplus.com/canvas/drawing-regular-polygons.html
// http://www.cnblogs.com/xcywt/p/9456526.html
// 圖像、中心點、半徑、邊數、旋轉角度、線寬
void EquilateralPolygon(Mat *src, Point origin, int radius, int brim, int rotate, int fill)
{
 if (brim < 3) return;
 if (rotate > 360) return;
 
#define PI 3.14159265
#define ROTATE_COUNT 180
 
 double nAgree = 360 / brim; // 計算旋轉角度
 double a = radius * cos(PI / brim);  // 計算垂直向下的長度
 double s = 2 * radius * sin(PI / brim); // 計算邊長
 
 vector<Point> Dots;
 Point D1, D2;
 D1.x = origin.x + radius*cos(-(((180 - nAgree) / 2) + rotate) * PI / 180);
 D1.y = origin.y - radius*sin(-(((180 - nAgree) / 2) + rotate) * PI / 180);
 D2.x = origin.x + radius*cos(-(((180 - nAgree) / 2) + nAgree + rotate) * PI / 180);
 D2.y = origin.y - radius*sin(-(((180 - nAgree) / 2) + nAgree + rotate) * PI / 180);
 
 // 第一條邊的兩個點
 Dots.push_back(D1);
 Dots.push_back(D2);
 
 for (int i = 0; i < brim - 2; i++)
 {
 double dSinRot = sin((nAgree * (i + 1)) * PI / 180);
 double dCosRot = cos((nAgree * (i + 1)) * PI / 180);
 int x = origin.x + dCosRot * (D2.x - origin.x) - dSinRot * (D2.y - origin.y);
 int y = origin.y + dSinRot * (D2.x - origin.x) + dCosRot * (D2.y - origin.y);
 Dots.push_back(Point(x, y));
 }
 Patterns(src, Dots, fill);
 Dots.clear();
}
 
int main()
{
 
 Mat Img = Mat::zeros(800, 800, CV_8UC3);
 Point O = Point(400, 400);
 
 circle(Img, O, 2, Scalar(0, 0, 255), -1); //中心點
 
 EquilateralPolygon(&Img, O, 100, 3, 0, -1); // 填充的正三角形
 EquilateralPolygon(&Img, O, 200, 3, 0, 1); // 不填充的正三角形
 EquilateralPolygon(&Img, O, 200, 3, 30, 1); // 不填充的正三角形,順時針旋轉30度
 EquilateralPolygon(&Img, O, 200, 3, 60, 1); // 不填充的正三角形,順時針旋轉60度
 EquilateralPolygon(&Img, O, 200, 3, 90, 1); // 不填充的正三角形,順時針旋轉90度
 EquilateralPolygon(&Img, O, 200, 3, 120, 1);// 不填充的正三角形,順時針旋轉120度
 EquilateralPolygon(&Img, O, 200, 3, 150, 1);// 不填充的正三角形,順時針旋轉150度
 EquilateralPolygon(&Img, O, 200, 3, 180, 1);// 不填充的正三角形,順時針旋轉180度
 
 EquilateralPolygon(&Img, O, 230, 4, 0, 2); // 不填充的正四邊形
 EquilateralPolygon(&Img, O, 250, 5, 0, 3); // 不填充的正五邊形
 EquilateralPolygon(&Img, O, 270, 6, 0, 4); // 不填充的正六邊形
 EquilateralPolygon(&Img, O, 290, 7, 0, 5); // 不填充的正七邊形
 EquilateralPolygon(&Img, O, 310, 8, 0, 6); // 不填充的正八邊形
 EquilateralPolygon(&Img, O, 330, 9, 0, 7); // 不填充的正九邊形
 EquilateralPolygon(&Img, O, 350, 10, 0, 8);// 不填充的正十邊形
 
 imshow("正多邊形", Img);
 waitKey(0);
 return 0;
}

效果如下: 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持我們。

上一篇:opencv利用霍夫變換檢測直線進行圖片校正

欄    目:C語言

下一篇:C++實現連連看游戲核心代碼

本文標題:OpenCV繪制正多邊形的方法

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/544.html

網頁制作CMS教程網絡編程軟件編程腳本語言數據庫服務器

如果侵犯了您的權利,請與我們聯(lián)系,我們將在24小時內進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網 版權所有