OpenCV 之图像篇 常用函数

来源:互联网 发布:unity3d虚拟现实 编辑:程序博客网 时间:2024/06/07 06:19

HighGUI Reference Manual

http://www.ai.rug.nl/vakinformatie/pas/content/Highgui/opencvref_highgui.htm

 

cpp文件前包含头文件


#include "cv.h"
#include "highgui.h"

 

 

需要包含的库文件


cv210.lib
cvaux210.lib
cxcore210.lib
highgui210.lib

 

经常会用到的图像函数

// Create a size

 

CvSize sz = cvSize( img->width & -2, img->height & -2 );

 

 

// Flip Image

 

cvConvertImage(resultImg, resultImg, CV_CVTIMG_FLIP);

切忌此函数不可用于通道(nChannel)超过3的iplImage,否则图像将失去原有的色调

 

 

// Allocate space for image

IplImage* image = cvCreateImage( imgSize, IPL_DEPTH_8U, 1);
IplImage* pyr = cvCreateImage( cvSize(sz.width/2, sz.height/2), 8, 3 );

// Change the color

 

cvCvtColor( difference,greyImage, CV_BGR2GRAY );

 

 

// Gaussian smooth


cvSmooth(image,image,CV_GAUSSIAN,7,7);

 

 

// Thresholding

 

cvThreshold(difference,difference,50,255,CV_THRESH_BINARY);

 

 

// Image show

 

cvShowImage("Output",output);

 

 

// Make a copy of image

 IplImage* timg = cvCloneImage( img );

 

 

// Create angle and scale


double angle = -90.0;
double scale = 1.0;
CvMat* rot_mat = cvCreateMat(2,3,CV_32FC1);
IplImage* dst = cvCreateImage( cvSize(resultImg->height, resultImg->width), 8, 1 );

 

cvConvertImage
// Compute rotation matrix


CvPoint2D32f center = cvPoint2D32f( resultImg->width/2, resultImg->height/2 );
cv2DRotationMatrix( center, angle, scale, rot_mat );    

 


// Do the transformation


cvWarpAffine( resultImg, dst, rot_mat );

 

 

// Copy an Image

 

cvCopy( timg, tgray, 0 );

 

 

// Clone an Image 

 

IplImage* dst = cvCloneImage(resultImg);

 

 

// Create window with name "image"

cvNamedWindow( "image", 1 );

 

 

// Resize Image

 

IplImage *imgB = resizeImage (imgIn, 1024, 768, false);

 


// Show image in window

cvShowImage("src", pImg);

 

 

// Save and Load Image

 

cvSaveImage(outFileName,img);

cvLoadImage(fileName);

img=cvLoadImage(fileName,flag);

flag: >0 the loaded image is forced to be a 3-channel color image

        =0 the loaded image is forced to be a 1 channel grayscale image

        <0 the loaded image is loaded as is (with number of channels in the file).

Supported image formats: BMP, DIB, JPEG, JPG, JPE, PNG, PBM, PGM, PPM, SR, RAS, TIFF, TIF

 

 

// Distrory window with name "image"

 cvDestroyWindow("image");

 

 

// Release memory space

 

cvReleaseImage( &newImg );

 

 

// Release Image after Distrory


cvReleaseImage(&pImg);

 

 

// Wait for key press

cvWaitKey(0);

 

 

// Capture a key press, but more importantly allow the window to refresh

key = cvWaitKey(1);

 

原创粉丝点击