3 #include <opencv2/core/core_c.h>
4 #include <opencv2/highgui/highgui_c.h>
5 #include <opencv2/imgproc/imgproc_c.h>
10 #define X_CORRECTION 200
12 int main(int argc, char *argv[])
16 IplImage *transformed_image;
20 CvMat *perspective_matrix;
23 fprintf(stderr, "usage: %s <image>\n", argv[0]);
28 image = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR);
30 fprintf(stderr, "Cannot load image\n");
35 cvNamedWindow("Viewport", 0);
36 cvResizeWindow("Viewport", WIDTH, HEIGHT);
38 /* Trasform only a part of the whole image */
41 viewport.width = WIDTH;
42 viewport.height = HEIGHT;
43 cvSetImageROI(image, viewport);
45 /* Calculate the prospective tranformation */
55 dst[0].x = X_CORRECTION;
57 dst[1].x = WIDTH - X_CORRECTION;
64 perspective_matrix = cvCreateMat(3, 3, CV_64F);
65 if (!perspective_matrix) {
66 fprintf(stderr, "Cannot create matrix\n");
68 goto out_destroy_window;
71 perspective_matrix = cvGetPerspectiveTransform(src, dst,
74 /* Create a new image and apply the prospective transformation */
75 transformed_image = cvCreateImage(cvSize(WIDTH, HEIGHT), image->depth,
77 if (!transformed_image) {
78 fprintf(stderr, "Cannot create trasnformed image\n");
83 cvWarpPerspective(image, transformed_image, perspective_matrix,
84 CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS,
87 cvShowImage("Viewport", transformed_image);
94 cvReleaseMat(&perspective_matrix);
96 cvDestroyWindow("Viewport");
97 cvReleaseImage(&image);