해당 포스트는 "OpenCV로 배우는 영상 처리 및 응용", "C++ API OpenCV 프로그래밍" 책의 내용을 요약한 것이다.



1. 직선 그리기

void line(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness = 1, int lineType = 8, int shift = 0)

: 영상 img에 pt1에서 pt2까지 연결하는 라인을 color 색상, thickness 두께로 라인을 그린다. lineType이 8 또는 4이면 8 또는 4픽셀 이웃을 사용하는 라인 알고리즘을 생성한다. lineType이 CV_AA이면 안티에일리징 라인을 생성한다. shift는 pt1과 pt2의 각 좌표를 shift 연산해 비트 이동시킨다. 만약 shift가 1이면 >>연산자가 적용되 나누기 2가 된다.


2. 사각형 그리기

void rectangle(Mat& img, Point pt1, Point pt2, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

: 영상 img에 pt1과 pt2로 정의되는 사각형을 그리되 color 색상, thickness 두께로 그린다. 단, thickness가 -1일 경우 사각형을 color로 채운다.


void rectangle(Mat& img, Rect rect, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

: 첫 번째 사각형 그리기와 비슷하다. 다만 사각형의 영역을 설정하는 변수가 Rect로 바꼈다.

3. 직선 클리핑
bool clipLine(Size imgSize, Point& pt1, Point& pt2)
bool clipLine(Rect imgRect, Point& pt1, Point& pt2)
: pt1에서 pt2를 잇는 직선이 imgSize/imgRect의 영역을 가지는 사각형과 만나는 점을 pt1과 pt2에 설정한다. imgSize에 의해 정의되는 사각형은 (0, 0, imgSize.width, imgSize.height)이다. 직선이 사각형 영역 밖에 있으면 false를 반환한다.

4. 직선 반복자(LineIterator)
: 직선 위의 영상의 좌표점을 순차적으로 알 수 있는 반복자 클래스이다. LineIterator::count는 라인 위 좌표점의 개수, LineIterator::pos 메서드는 현재 위치의 좌표를 반환한다.

5. 원 그리기
void circle(Mat& img, Point center, int radius, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
: center 좌표를 원의 중심으로 한 반지름 radius의 원을 그린다. 나머지 변수는 rectangle 메서드와 같은 역할을 한다.


6. 타원 그리기

void ellipse(Mat& img, Point center, Size axes, double angle, double startAngle, double endAngle, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

: ellipse 함수는 영상 img에 중심점 center, 주축 크기의 절반 axes, 수평추고가의 회전 각도 angle, 호의 시작과 끝의 각도는 startAngle, endAngle인 타원을 그린다. startAngle =0, endAngle=360이면 닫힌 타원을 그린다.


void ellipse(Mat& img, const RotatedRect& box, const Scalar& color, int thickness=1, int lineType=8, int shift=0)

: 영상 img에 RotatedRect 클랫의 회전된 사각형 box에 내접하는 타원을 그린다.


void ellipse2Poly(Point center, Size axes, int angle, int arcStart, int arcEnd, int delta, vector<Point>& pts)

: 위의 매개 변수에 의해 정위되는 타원 위의 좌표를 delta 각도 간격으로 계산하여 벡터 pts에 저장한다.


7. 다각형 그리기 및 채우기
void polylines(Mat& img, const Point** pts, const int* npts, int ncontours, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
: 영상 img에 pts에 저장된 좌표점을 연결하는 다각형들을 그린다. pts가 이중 포인터로 되어 있어 여러 개의 다각형을 저장할 수 있는 데 저장할 다각형의 개수는 ncontours에 명시한다. npts는 각 다각형의 꼭짓점 개수를 가리킨다. 

void polylines(InputOutputArray img, InputArrayOfArrays pts, bool isClosed, const Scalar& color, int thickness=1, int lineType=8, int shift=0)
: 영상 img에 Mat 행렬 또는 벡터 등의 pts에 저장된 좌표점을 연결하는 다각형을 그린다. isClosed=true이면 닫힌 다각형을 그린다.

void fillConvexPoly(Mat& img const Point* pts, int npts, const Scalar& color, int lineType=8, int shift=0)
: 영상 img에 pts에 저장된 npts 개수의 좌표점으로 구성된 블록 다각형을 그린다. fillPoly 함수보다 빠르게 실행된다.

void fillPoly(Mat& img, const Point** pts, const int* npts, int ncontours, const Scalar& color, int lineType=8, int shift=0, Point offset=Point())
: img에 Point의 이중 포인터 pts에 저장된 ncontours 개의 다각형을 그린다. offset은 각 다각형의 모든 좌표 점에 더해지는 좌표이다.

8. 문자열 출력
Size getTextSize(const string& text, int fontFace, double fontScale, int thickness, int* baseLine)
: putText로 출력된 문자열의 크기를 계산한다. 

void putText(Mat& img, const string& text, Point org, int fontFace, double fontScale, Scalar color, int thickness=1, int lineType=8, bool bottomLeftOrigin = false)
: 영상 img에 text를 출력한다. org는 출력할 위치를 가리킨다.


+ Recent posts