#include <cv.h> #include <highgui.h> #include <stdio.h> #pragma comment(lib, "cv.lib") #pragma comment(lib, "cxcore.lib") #pragma comment(lib, "highgui.lib") char name0[] = "lena.bmp"; int main_1() { IplImage* imagen = NULL; imagen = cvLoadImage(name0,1); int px = 200; int py = 400; IplImage *resized = cvCreateImage(cvSize(px, py),IPL_DEPTH_8U, 3); cvResize(imagen, resized, CV_INTER_LINEAR); cvNamedWindow("test"); cvShowImage("test", resized); cvWaitKey(0); cvDestroyAllWindows(); cvReleaseImage(&imagen); cvReleaseImage(&resized); return 0; } int main_2() { IplImage* imagen = NULL; imagen = cvLoadImage(name0,1); IplImage *rotated = cvCreateImage(cvGetSize(imagen), IPL_DEPTH_8U, imagen->nChannels); CvPoint2D32f center; int angle = 30; CvMat *mapMatrix = cvCreateMat(2,3,CV_32FC1); center.x=160; center.y=120; cv2DRotationMatrix(center,angle,1.0,mapMatrix); cvWarpAffine(imagen, rotated, mapMatrix, CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, cvScalarAll(0)); cvNamedWindow("origen"); cvShowImage("origen", imagen); cvNamedWindow("resultado"); cvShowImage("resultado",rotated); cvWaitKey(0); cvDestroyAllWindows(); cvReleaseImage(&imagen); cvReleaseImage(&rotated); cvReleaseMat(&mapMatrix); return 0; } int main_3(int argc, char** argv) { IplImage* src; src = cvLoadImage(name0); IplImage* dst = cvCloneImage(src); int angle = -25; float m[6]; CvMat M = cvMat(2, 3, CV_32F, m); int w = src->width; int h = src->height; m[0] = (float)(cos(-angle*2*CV_PI/180.)); m[1] = (float)(sin(-angle*2*CV_PI/180.)); m[2] = w * 0.5f; m[3] = -m[1]; m[4] = m[0]; m[5] = h*0.5f; cvGetQuadrangleSubPix(src, dst, &M); cvNamedWindow("origen"); cvShowImage("origen", src); cvNamedWindow("resultado"); cvShowImage("resultado", dst); cvWaitKey(0); cvDestroyAllWindows(); cvReleaseImage(&dst); cvReleaseImage(&src); return 0; } int main() { IplImage* src; IplImage* colorThresh; IplImage* gray; IplImage* grayThresh; int threshold = 120; int maxValue = 255; int thresholdType = CV_THRESH_BINARY; src = cvLoadImage(name0, 1); colorThresh = cvCloneImage( src ); gray=cvCreateImage( cvSize(src->width, src->height), IPL_DEPTH_8U, 1 ); cvCvtColor( src, gray, CV_BGR2GRAY ); grayThresh = cvCloneImage( gray ); cvNamedWindow( "src", 1 ); cvShowImage( "src", src ); cvNamedWindow( "gray", 1 ); cvShowImage( "gray", gray ); cvThreshold(src, colorThresh, threshold, maxValue, thresholdType); cvThreshold(gray, grayThresh, threshold, maxValue, thresholdType); cvNamedWindow( "colorThresh", 1 ); cvShowImage( "colorThresh", colorThresh ); cvNamedWindow( "grayThresh", 1 ); cvShowImage( "grayThresh", grayThresh ); cvWaitKey(0); cvDestroyWindow( "src" ); cvDestroyWindow( "colorThresh" ); cvDestroyWindow( "gray" ); cvDestroyWindow( "grayThresh" ); cvReleaseImage( &src ); cvReleaseImage( &colorThresh ); cvReleaseImage( &gray ); cvReleaseImage( &grayThresh ); return 0; }