2017-04-11 1 views
0

opencv에서 회전 된 사각형을 C++로 그려야합니다. 나는 "rectangle" 기능 울부 짖는 소리처럼 사용opencv에서 회전 된 사각형 그리기 C++

rectangle(RGBsrc, vertices[0], vertices[2], Scalar(0, 0, 0), CV_FILLED, 8, 0); 

하지만이 기능은 0 각도를 가진 사각형을 그립니다. opencv에서 C++을 사용하여 회전 된 사각형을 특별한 각도로 그릴 수 있습니까? 당신이 채워진 사각형을 원하기 때문에

+1

당신은 회전 된 사각형의 네 모서리 사이에 4 별도의 선을 그릴해야합니다. – sgarizvi

+0

[THIS PAGE] (http://docs.opencv.org/trunk/db/dd6/classcv_1_1RotatedRect.html) 도움이 될 수 있습니다. –

답변

1

, 당신은 fillConvexPoly을 사용해야합니다

// Include center point of your rectangle, size of your rectangle and the degrees of rotation 
void DrawRotatedRectangle(cv::Mat& image, cv::Point centerPoint, cv::Size rectangleSize, double rotationDegrees) 
{ 
    cv::Scalar color = cv::Scalar(255.0, 255.0, 255.0) // white 

    // Create the rotated rectangle 
    cv::RotatedRect rotatedRectangle(centerPoint, rectangleSize, rotationDegrees); 

    // We take the edges that OpenCV calculated for us 
    cv::Point2f vertices2f[4]; 
    rotatedRectangle.points(vertices2f); 

    // Convert them so we can use them in a fillConvexPoly 
    cv::Point vertices[4];  
    for(int i = 0; i < 4; ++i){ 
     vertices[i] = vertices2f[i]; 
    } 

    // Now we can fill the rotated rectangle with our specified color 
    cv::fillConvexPoly(image, 
         vertices, 
         4, 
         color); 
}