아래는 테스트 영상(좌)과 변환된 영상(우)이다. 변환된 영상의 크기는 대상 문서의 크기와 동일하다.
![]() | ![]() |
소스코드는 아래를 참조한다.
more..
#include <stdio.h>
#include <stdlib.h>
#include <cv.h>
#include <highgui.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
int main(int argc, char **argv)
{
IplImage *in, *out;
CvPoint2D32f src[4], dst[4];
CvMat *h = NULL;
int width, height;
if (argc != 3) {
fprintf(stderr, "Usage: %s in out\n", argv[0]);
exit(EXIT_FAILURE);
}
/* top left */
src[0].x = 194;
src[0].y = 108;
/* top right */
src[1].x = 1386;
src[1].y = 118;
/* bottom right (not left!!) */
src[2].x = 1508;
src[2].y = 1936;
/* bottom left */
src[3].x = 32;
src[3].y = 1916;
width = max(src[1].x - src[0].x, src[2].x - src[3].x);
height = max(src[3].y - src[0].y, src[2].y - src[1].y);
/* top left */
dst[0].x = 0;
dst[0].y = 0;
/* top right */
dst[1].x = width;
dst[1].y = 0;
/* bottom right (not left!!) */
dst[2].x = width;
dst[2].y = height;
/* bottom left */
dst[3].x = 0;
dst[3].y = height;
in = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
out = cvCreateImage(cvSize(width, height), in->depth, in->nChannels);
h = cvCreateMat(3, 3, CV_32FC1);
cvGetPerspectiveTransform(src, dst, h);
cvWarpPerspective(in, out, h, CV_INTER_CUBIC + CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
cvSaveImage(argv[2], out, NULL);
cvReleaseMat(&h);
cvReleaseImage(&in);
cvReleaseImage(&out);
return 0;
}
#include <stdlib.h>
#include <cv.h>
#include <highgui.h>
#define max(a, b) ((a) > (b) ? (a) : (b))
int main(int argc, char **argv)
{
IplImage *in, *out;
CvPoint2D32f src[4], dst[4];
CvMat *h = NULL;
int width, height;
if (argc != 3) {
fprintf(stderr, "Usage: %s in out\n", argv[0]);
exit(EXIT_FAILURE);
}
/* top left */
src[0].x = 194;
src[0].y = 108;
/* top right */
src[1].x = 1386;
src[1].y = 118;
/* bottom right (not left!!) */
src[2].x = 1508;
src[2].y = 1936;
/* bottom left */
src[3].x = 32;
src[3].y = 1916;
width = max(src[1].x - src[0].x, src[2].x - src[3].x);
height = max(src[3].y - src[0].y, src[2].y - src[1].y);
/* top left */
dst[0].x = 0;
dst[0].y = 0;
/* top right */
dst[1].x = width;
dst[1].y = 0;
/* bottom right (not left!!) */
dst[2].x = width;
dst[2].y = height;
/* bottom left */
dst[3].x = 0;
dst[3].y = height;
in = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
out = cvCreateImage(cvSize(width, height), in->depth, in->nChannels);
h = cvCreateMat(3, 3, CV_32FC1);
cvGetPerspectiveTransform(src, dst, h);
cvWarpPerspective(in, out, h, CV_INTER_CUBIC + CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
cvSaveImage(argv[2], out, NULL);
cvReleaseMat(&h);
cvReleaseImage(&in);
cvReleaseImage(&out);
return 0;
}



comments
comments rss (+댓글 쓰러가기)