Created
November 11, 2010 16:52
-
-
Save yoggy/672785 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// cvaddimage.c | |
// | |
// how to compile: | |
// | |
// $ gcc -I/usr/local/opencv2.1/include/ -std=c99 -L/usr/local/opencv2.1/lib -lhighgui -lcv -lcxcore -o cvaddimage cvaddimage.c | |
// $ DYLD_LIBRARY_PATH=/usr/local/opencv2.1/lib ./cvmattest | |
// | |
// how to run | |
// | |
// ./cvaddimage background_image foreground_image x y width height | |
// | |
// example: | |
// | |
// $ ./cvaddimage a.png b.png result.png 100 200 320 240 | |
// | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <opencv/cv.h> | |
#include <opencv/cxcore.h> | |
#include <opencv/highgui.h> | |
int | |
main(int argc, char *argv[]) | |
{ | |
int x = atoi(argv[4]); | |
int y = atoi(argv[5]); | |
int w = atoi(argv[6]); | |
int h = atoi(argv[7]); | |
IplImage *background_img = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR); | |
IplImage *foreground_img = cvLoadImage(argv[2], CV_LOAD_IMAGE_COLOR); | |
IplImage *resize_img = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 3); | |
IplImage *result_img = cvCreateImage(cvGetSize(background_img), IPL_DEPTH_8U, 3); | |
// 背景をコピー | |
cvCopy(background_img, result_img, NULL); | |
// 前景をリサイズ | |
cvResize(foreground_img, resize_img, CV_INTER_NN); | |
// イメージを重ねる(foreground_imgはbackground_imgよりも小さい前提w) | |
cvSetImageROI(result_img, cvRect(x, y, w, h)); | |
cvCopy(resize_img, result_img, NULL); | |
cvResetImageROI(result_img); | |
cvSaveImage(argv[3], result_img, 0); | |
//cvSaveImage(argv[3], result_img); // old opencv style... | |
cvReleaseImage(&background_img); | |
cvReleaseImage(&foreground_img); | |
cvReleaseImage(&resize_img); | |
cvReleaseImage(&result_img); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment