| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | 7 |
| 8 | 9 | 10 | 11 | 12 | 13 | 14 |
| 15 | 16 | 17 | 18 | 19 | 20 | 21 |
| 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Tags
- tensorflow update
- python __init__
- 딥러닝
- Convolution Neural Network
- 영어
- convexhull
- findContours
- object detection
- python 알고리즘
- opencv SURF
- 영어명언
- python list
- 이미지 생성
- tokenizing
- #영어 명언
- keras
- #opencv
- c언어
- TensorFlow
- #실생활 영어
- #프로젝트
- text2img
- #일상영어
- 완전탐색
- #영어
- #Android
- #English
- word embedding
- #1일1영어
- #실생활영어
Archives
- Today
- Total
When will you grow up?
20.Affine Transformation 본문
Affine Transformation(아핀변환)
->하나의 가하체(이미지==Mat)에 아핀변환을 적용하게 되면 변환된 기하체는 원래 기하체와 평행관계를 유지하게 됩니다. 기하체의 이동, 회전, 스케일(scale), 그리고shear 등이 아핀변환에 해당됩니다.
[출처] 아핀변환(affine transformation)|작성자 Keychany
사용될 함수 원형입니다.
cv::warpAffine : 원본이미지를 Affine변환 시킨다.
| void cv::warpAffine | ( | InputArray | src,//입력이미지 |
| OutputArray | dst,//출력이미지 | ||
| InputArray | M,//2*3 transformation matrix | ||
| Size | dsize,//출력이미지사이즈 | ||
| int | flags = INTER_LINEAR, | ||
| int | borderMode = BORDER_CONSTANT, | ||
| const Scalar & | borderValue = Scalar() | ||
| ) |
cv::getRotationMatrix2D :Affine변환된 Mat를 회전 및 크기변환을 시킬수있다.
(회전시킬중심점,각도,크기)
| Mat cv::getRotationMatrix2D | ( | Point2f | center, |
| double | angle, | ||
| double | scale | ||
| ) |
결과입니다.
전체 소스 코드입니다.
#include "ofApp.h"
using namespace std;
void ofApp::setup() {
//결과를 저장할 Mat과 Affine Transform을 정의하는 2D점을 저장하는 배열 선언
Point2f srcTri[3];//2D점을 저장하는 원본배열 선언
Point2f dstTri[3];//2D점을 저장하는 결과배열 선언
Mat rot_mat(2, 3, CV_32FC1);//3행 2열,32비트 실수형 채널1 Mat 생성
Mat warp_mat(2, 3, CV_32FC1);//3행 2열,32비트 실수형 채널1 Mat 생성
Mat src, warp_dst, warp_rotate_dst;
src = imread("1111.jpg",1);
warp_dst = Mat::zeros(src.rows, src.cols, src.type());//src이미지 행과 열 크기만큼 와 같은 타입으로 값은 0으로 설정
imshow("원본", src);
srcTri[0] = Point2f(0, 0);
srcTri[1] = Point2f(src.cols - 1.f, 0);//src.cols이 620일 가정 ->[619,0]
srcTri[2] = Point2f(0, src.rows - 1.f);//src.rows이 607일 가정 ->[606,0]
dstTri[0] = Point2f(src.cols*0.0f, src.rows*0.33f);//src.cols이 620,src.rows 607일 가정 [0, 200.31]
dstTri[1] = Point2f(src.cols*0.85f, src.rows*0.25f);//src.cols이 620,src.rows 607일 가정 [527,151.75]
dstTri[2] = Point2f(src.cols*0.15f, src.rows*0.7f);//src.cols이 620,src.rows 607일 가정 [93, 424.9]
warp_mat = getAffineTransform(srcTri, dstTri);//입력 매칭쌍으로 부터 affine변환을 구해서 warp_mat에 넣어줌
warpAffine(src, warp_dst, warp_mat, warp_dst.size());//입력,출력,affine변형,출력이미지원하는 크기 만큼 affine변환시킨다.
imshow("warp", warp_dst);
//angle = 0,scale = 0.6
Point center = Point(warp_dst.cols / 2, warp_dst.rows / 2);//warp_dst이미지 중앙점을 넣는다.
double angle = 0;
double scale = 0.6;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+scale=0.6", warp_rotate_dst);
//angle = 30,scale = 0.6
angle = 30.0;
scale = 0.6;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+(scale=0.6,rotation1 = 30.0)", warp_rotate_dst);
//angle = -30,scale = 0.6
angle = -30.0;
scale = 0.6;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+(scale=-0.6,rotation = -30.0)", warp_rotate_dst);
//angle = 0,scale = 1.5
angle = 0;
scale = 1.5;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+(scale=1.5,rotation = 0.0)", warp_rotate_dst);
//angle = 45,scale = 1.5
angle = 45;
scale = 1.5;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+(scale=1.5,rotation = 45.0)", warp_rotate_dst);
//angle = -45,scale = 1.5
angle = -45;
scale = 1.5;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+(scale=1.5,rotation = -45.0)", warp_rotate_dst);
//angle = 0,scale = 1
angle = 0;
scale = 1;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+(scale=1.0,rotation = 0.0)", warp_rotate_dst);
//angle = 75,scale = 1
angle = 75;
scale = 1;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+(scale=1.0,rotation = 75.0)", warp_rotate_dst);
//angle = -75,scale = 1
angle = -75;
scale = 1;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
imshow("warp+(scale=1.0,rotation = -75.0)", warp_rotate_dst);
//angle = -75,scale = 1 , BORDER_ISOLATED
angle = -75;
scale = 1;
rot_mat = getRotationMatrix2D(center, angle, scale);//2d 회전 affine행렬 계산 ,중심으로부터 angle,scale변환
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size(), BORDER_ISOLATED);
imshow("warp+(scale=1.0,rotation = -75.0,BORDER_ISOLATED)", warp_rotate_dst);
}
//--------------------------------------------------------------
void ofApp::update() {
}
//--------------------------------------------------------------
void ofApp::draw() {
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key) {
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y) {
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button) {
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button) {
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button) {
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y) {
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y) {
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h) {
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg) {
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo) {
}
'02. Study > Computer Vision(openframworks&opencv)' 카테고리의 다른 글
| opencv로 Panorama Image 만들기 (0) | 2016.11.26 |
|---|---|
| 21. Perspective Transformation(투영변환) (0) | 2016.11.25 |
| 19_1.Convex Hull (Graham's Scan 알고리즘 활용) (0) | 2016.11.08 |
| 19.convexHull (0) | 2016.11.07 |
| 18.contour(윤곽,외곽선)찾기 findContours (0) | 2016.11.07 |
Comments