Initial import
authorAntonio Ospite <ospite@studenti.unina.it>
Tue, 19 Mar 2013 12:04:13 +0000 (13:04 +0100)
committerAntonio Ospite <ospite@studenti.unina.it>
Tue, 19 Mar 2013 12:04:13 +0000 (13:04 +0100)
DOCS.txt [new file with mode: 0644]
image-roi/Makefile [new file with mode: 0644]
image-roi/opencv-image-roi.c [new file with mode: 0644]
image-roi/road.png [new file with mode: 0644]
perspective-transform/Makefile [new file with mode: 0644]
perspective-transform/opencv-perspective-transform.c [new file with mode: 0644]
perspective-transform/road.png [new file with mode: 0644]

diff --git a/DOCS.txt b/DOCS.txt
new file mode 100644 (file)
index 0000000..a251700
--- /dev/null
+++ b/DOCS.txt
@@ -0,0 +1,2 @@
+http://opencv.willowgarage.com/documentation/index.html
+http://opencv-code.com
diff --git a/image-roi/Makefile b/image-roi/Makefile
new file mode 100644 (file)
index 0000000..758992c
--- /dev/null
@@ -0,0 +1,35 @@
+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
diff --git a/image-roi/opencv-image-roi.c b/image-roi/opencv-image-roi.c
new file mode 100644 (file)
index 0000000..5e2ced1
--- /dev/null
@@ -0,0 +1,60 @@
+/* 
+ * 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;
+}
diff --git a/image-roi/road.png b/image-roi/road.png
new file mode 100644 (file)
index 0000000..48ae0c9
Binary files /dev/null and b/image-roi/road.png differ
diff --git a/perspective-transform/Makefile b/perspective-transform/Makefile
new file mode 100644 (file)
index 0000000..3e788b7
--- /dev/null
@@ -0,0 +1,35 @@
+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
diff --git a/perspective-transform/opencv-perspective-transform.c b/perspective-transform/opencv-perspective-transform.c
new file mode 100644 (file)
index 0000000..672795a
--- /dev/null
@@ -0,0 +1,100 @@
+#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;
+}
diff --git a/perspective-transform/road.png b/perspective-transform/road.png
new file mode 100644 (file)
index 0000000..48ae0c9
Binary files /dev/null and b/perspective-transform/road.png differ