0
OpenCvで特定の半径のcircle
をpolygon
(たとえば、五角形や六角形など)に変換する方法があるのだろうか?OpenCv円を多角形に変換する
サークルは非常に簡単です:
cv::circle(myMat, center_point, radius, colour, 2, 16);
やポリゴンも同様に簡単です:
cv::polylines(myMat, points, isClosed, colour, 2, 16);
私のアプローチは以下の通りです:
作業が、私はしたさint length = 150;
Point center_point(500, 500);
Point P1;
P1.x = (int)round(center_point.x + length * cos(0 * CV_PI/180.0));
P1.y = (int)round(center_point.y + length * sin(0 * CV_PI/180.0));
Point P2;
P2.x = (int)round(center_point.x + length * cos(45 * CV_PI/180.0));
P2.y = (int)round(center_point.y + length * sin(45 * CV_PI/180.0));
Point P3;
P3.x = (int)round(center_point.x + length * cos(90 * CV_PI/180.0));
P3.y = (int)round(center_point.y + length * sin(90 * CV_PI/180.0));
Point P4;
P4.x = (int)round(center_point.x + length * cos(135 * CV_PI/180.0));
P4.y = (int)round(center_point.y + length * sin(135 * CV_PI/180.0));
Point P5;
P5.x = (int)round(center_point.x + length * cos(180 * CV_PI/180.0));
P5.y = (int)round(center_point.y + length * sin(180 * CV_PI/180.0));
Point P6;
P6.x = (int)round(center_point.x + length * cos(225 * CV_PI/180.0));
P6.y = (int)round(center_point.y + length * sin(225 * CV_PI/180.0));
Point P7;
P7.x = (int)round(center_point.x + length * cos(270 * CV_PI/180.0));
P7.y = (int)round(center_point.y + length * sin(270 * CV_PI/180.0));
Point P8;
P8.x = (int)round(center_point.x + length * cos(315 * CV_PI/180.0));
P8.y = (int)round(center_point.y + length * sin(315 * CV_PI/180.0));
cv::polylines(myMat, {P1,P2,P3,P4,P5,P6,P7,P8}, isClosed, colour, 2, 16);
それを行うより巧妙な方法があるかどうか疑問に思っていますか?
とても簡単です。ありがとう – user1234