02. Study/Computer Vision(openframworks&opencv)
21. Perspective Transformation(투영변환)
미카이
2016. 11. 25. 17:29
Perspective Transformation == Homography Matrix == Projective Transformation
(세 용어다 각각 차이점은 존재하지만 개념상 같은 개념이라고 생각을 해도 된다.)
Homograhpy
한 평면을 다른 평면에 투영(Projection) 시켰을 때, 투영된 대응점들 사이에서는 일정한 변환 관계가 성립한다. 이 변환 관계를 Homography라고 한다.
->카메라 위치 수정 이나 환자의 자세 등 이미지 일정 부분 확대시 이용하는 변환
4개의 점와 와핑된 이미지를 이용하여 변환행렬을 구해주면 된다.
결과
원본이미지
결과 이미지
원본 코드 입니다.
// 인풋 이미지 평면 좌표 입력 Point2f inputQuad[4]; // 출력 이미지 평면 좌표 Point2f outputQuad[4]; // Lambda Matrix Mat lambda(2, 4, CV_32FC1); //Mat 형식의 입력,출력 이미지 Mat input, output; input = imread("LOL.jpg",1); // Set the lambda matrix the same type and size as input lambda = Mat::zeros(input.rows, input.cols, input.type()); // 4점 포인트를 시계방향으로 설정해준다 inputQuad[0] = Point2f(184, 35);//왼쪽위 inputQuad[1] = Point2f(413, 36);//오른쪽위 inputQuad[2] = Point2f(592, 242);//오른쪽아래 inputQuad[3] = Point2f(6, 264);//왼쪽아래 // 맵핑될 이미지를 시계방향으로 잡아준다. outputQuad[0] = Point2f(0, 0); outputQuad[1] = Point2f(input.cols - 1, 0); outputQuad[2] = Point2f(input.cols - 1, input.rows - 1); outputQuad[3] = Point2f(0, input.rows - 1); // 입력,출력 Quad를 통해 getPerspectiveTransform함수를 이용하여 변환행렬을 구함 lambda = getPerspectiveTransform(inputQuad, outputQuad); // 이미지 와핑 warpPerspective(input, output, lambda, output.size());//입력,출력,변환행렬,크기 //Display input and output imshow("Input", input); imshow("Output", output); waitKey(0);
레퍼런스
: http://blog.daum.net/shksjy/240
: http://miatistory.tistory.com/5
: opencv 도큐먼트