opencv 공부 중 회전하는 사각형 2개를 포함하는 bounding 사각형을 만들어야 되는데 or연산자로 간단하게 해결했다.
#include <opencv2\opencv.hpp>
#include <stdlib.h>
using namespace cv;
using namespace std;
int main() {
for (int deg = 360; deg > 0; deg += -10) {
Mat image(1000, 1000, CV_8UC1, Scalar(255));
Point2f center(250, 200), pts[4];
Point2f center2(500, 350), pts2[4];
Size2f size(200, 100);
Size2f size2(150, 150);
RotatedRect rot_rect(center, size, deg); // constant is angle
RotatedRect rot_rect2(center2, size2, deg);
Rect bound_rect = rot_rect.boundingRect();
Rect bound_rect2 = rot_rect2.boundingRect();
rectangle(image, bound_rect|bound_rect2, Scalar(0), 1);
circle(image, rot_rect.center, 1, Scalar(0), 2);
circle(image, rot_rect2.center, 1, Scalar(0), 2);
rot_rect.points(pts);
rot_rect2.points(pts2);
for (int i = 0; i < 4; i++) {
circle(image, pts[i], 14, Scalar(0), 1); // 꼭지점 생성, 두번째 매개변수는 원의 크기
line(image, pts[i], pts[(i + 1) % 4], Scalar(0), 2); // 라인 생성, 다섯번째 매개변수는 라인의 두께
circle(image, pts2[i], 14, Scalar(0), 1);
line(image, pts2[i], pts2[(i + 1) % 4], Scalar(0), 2);
}
imshow("회전사각형", image);
waitKey(100);
}
return 0;
}
'C++ > OpenCV' 카테고리의 다른 글
[OpenCV]vector 클래스 (0) | 2019.04.11 |
---|---|
[OpenCV]Mat_ 클래스와 Matx 클래스 (0) | 2019.04.10 |
[OpenCV]Mat 클래스 (0) | 2019.04.10 |
[OpenCV]RotatedRect 클래스 (0) | 2019.04.10 |
OpenCV의 기본 자료 구조 (0) | 2019.04.10 |