--- /dev/null
+http://opencv.willowgarage.com/documentation/index.html
+http://opencv-code.com
--- /dev/null
+CFLAGS = -ansi -pedantic -pedantic-errors -Wall -g3 -O2 -D_ANSI_SOURCE_
+CFLAGS += -fno-common \
+ -Wall \
+ -Wdeclaration-after-statement \
+ -Wextra \
+ -Wformat=2 \
+ -Winit-self \
+ -Winline \
+ -Wpacked \
+ -Wp,-D_FORTIFY_SOURCE=2 \
+ -Wpointer-arith \
+ -Wlarger-than-65500 \
+ -Wmissing-declarations \
+ -Wmissing-format-attribute \
+ -Wmissing-noreturn \
+ -Wmissing-prototypes \
+ -Wnested-externs \
+ -Wold-style-definition \
+ -Wredundant-decls \
+ -Wsign-compare \
+ -Wstrict-aliasing=2 \
+ -Wstrict-prototypes \
+ -Wswitch-enum \
+ -Wundef \
+ -Wunreachable-code \
+ -Wunsafe-loop-optimizations \
+ -Wunused-but-set-variable \
+ -Wwrite-strings
+
+LDLIBS = -lopencv_core -lopencv_highgui
+
+opencv-image-roi: opencv-image-roi.o
+
+clean:
+ rm -rf *~ *.o opencv-image-roi
--- /dev/null
+/*
+ * opencv-image-roi - Example program for cvSetImageROI()
+ *
+ * Copyright (C) 2013 Antonio Ospite <ospite@studenti.unina.it>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+#include <errno.h>
+#include <opencv2/core/core_c.h>
+#include <opencv2/highgui/highgui_c.h>
+
+#define WIDTH 800
+#define HEIGHT 480
+
+int main(int argc, char *argv[])
+{
+ IplImage *image;
+ CvRect viewport;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s <image>\n", argv[0]);
+ return -EINVAL;
+ }
+
+ image = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR);
+ if (!image) {
+ fprintf(stderr, "Cannot load image\n");
+ return -EINVAL;
+ }
+
+ cvNamedWindow("Viewport", 0);
+ cvResizeWindow("Viewport", WIDTH, HEIGHT);
+
+ viewport.x = 0;
+ viewport.y = 0;
+ viewport.width = WIDTH;
+ viewport.height = HEIGHT;
+ cvSetImageROI(image, viewport);
+
+ cvShowImage("Viewport", image);
+
+ cvWaitKey(0);
+
+ cvDestroyWindow("Viewport");
+ cvReleaseImage(&image);
+ return 0;
+}
--- /dev/null
+CFLAGS = -ansi -pedantic -pedantic-errors -Wall -g3 -O2 -D_ANSI_SOURCE_
+CFLAGS += -fno-common \
+ -Wall \
+ -Wdeclaration-after-statement \
+ -Wextra \
+ -Wformat=2 \
+ -Winit-self \
+ -Winline \
+ -Wpacked \
+ -Wp,-D_FORTIFY_SOURCE=2 \
+ -Wpointer-arith \
+ -Wlarger-than-65500 \
+ -Wmissing-declarations \
+ -Wmissing-format-attribute \
+ -Wmissing-noreturn \
+ -Wmissing-prototypes \
+ -Wnested-externs \
+ -Wold-style-definition \
+ -Wredundant-decls \
+ -Wsign-compare \
+ -Wstrict-aliasing=2 \
+ -Wstrict-prototypes \
+ -Wswitch-enum \
+ -Wundef \
+ -Wunreachable-code \
+ -Wunsafe-loop-optimizations \
+ -Wunused-but-set-variable \
+ -Wwrite-strings
+
+LDLIBS = -lopencv_core -lopencv_highgui -lopencv_imgproc
+
+opencv-perspective-transform: opencv-perspective-transform.o
+
+clean:
+ rm -rf *~ *.o opencv-perspective-transform
--- /dev/null
+#include <stdio.h>
+#include <errno.h>
+#include <opencv2/core/core_c.h>
+#include <opencv2/highgui/highgui_c.h>
+#include <opencv2/imgproc/imgproc_c.h>
+
+#define WIDTH 800
+#define HEIGHT 480
+
+#define X_CORRECTION 200
+
+int main(int argc, char *argv[])
+{
+ int ret;
+ IplImage *image;
+ IplImage *transformed_image;
+ CvRect viewport;
+ CvPoint2D32f src[4];
+ CvPoint2D32f dst[4];
+ CvMat *perspective_matrix;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s <image>\n", argv[0]);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ image = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR);
+ if (!image) {
+ fprintf(stderr, "Cannot load image\n");
+ ret = -EINVAL;
+ goto out;
+ }
+
+ cvNamedWindow("Viewport", 0);
+ cvResizeWindow("Viewport", WIDTH, HEIGHT);
+
+ /* Trasform only a part of the whole image */
+ viewport.x = 0;
+ viewport.y = 0;
+ viewport.width = WIDTH;
+ viewport.height = HEIGHT;
+ cvSetImageROI(image, viewport);
+
+ /* Calculate the prospective tranformation */
+ src[0].x = 0;
+ src[0].y = 0;
+ src[1].x = WIDTH;
+ src[1].y = 0;
+ src[2].x = WIDTH;
+ src[2].y = HEIGHT;
+ src[3].x = 0;
+ src[3].y = HEIGHT;
+
+ dst[0].x = X_CORRECTION;
+ dst[0].y = 0;
+ dst[1].x = WIDTH - X_CORRECTION;
+ dst[1].y = 0;
+ dst[2].x = WIDTH;
+ dst[2].y = HEIGHT;
+ dst[3].x = 0;
+ dst[3].y = HEIGHT;
+
+ perspective_matrix = cvCreateMat(3, 3, CV_64F);
+ if (!perspective_matrix) {
+ fprintf(stderr, "Cannot create matrix\n");
+ ret = -EINVAL;
+ goto out_destroy_window;
+ }
+
+ perspective_matrix = cvGetPerspectiveTransform(src, dst,
+ perspective_matrix);
+
+ /* Create a new image and apply the prospective transformation */
+ transformed_image = cvCreateImage(cvSize(WIDTH, HEIGHT), image->depth,
+ image->nChannels);
+ if (!transformed_image) {
+ fprintf(stderr, "Cannot create trasnformed image\n");
+ ret = -EINVAL;
+ goto out_release_mat;
+ }
+
+ cvWarpPerspective(image, transformed_image, perspective_matrix,
+ CV_INTER_LINEAR | CV_WARP_FILL_OUTLIERS,
+ cvScalarAll(0));
+
+ cvShowImage("Viewport", transformed_image);
+
+ cvWaitKey(0);
+
+ ret = 0;
+
+out_release_mat:
+ cvReleaseMat(&perspective_matrix);
+out_destroy_window:
+ cvDestroyWindow("Viewport");
+ cvReleaseImage(&image);
+out:
+ return ret;
+}