*****************/ #include <cv.h> #include <highgui.h> int main() { char* filePath ="D:/图片库/Lena.jpg"; IplImage* srcImg = cvLoadImage(filePath); IplImage* greyImg = cvCreateImage(cvGetSize(srcImg), srcImg->depth, 1); IplImage* cannyImg = cvCreateImage(cvGetSize(greyImg), srcImg->depth, 1); CvSize dstSize; dstSize.width = srcImg->width *3.0; dstSize.height = srcImg->height; IplImage* dstImg = cvCreateImage(dstSize, srcImg->depth, srcImg->nChannels); cvZero(dstImg); cvConvertImage(srcImg, greyImg); cvCanny(greyImg, cannyImg, 150, 100); //---------------------------------- //载入原图像到目标图像 cvSetImageROI(dstImg, cvRect(0, 0, srcImg->width, srcImg->height)); cvCopy(srcImg, dstImg); cvResetImageROI(dstImg); //载入灰度图像到目标图像 cvSetImageROI(dstImg, cvRect(srcImg->width, 0, srcImg->width, srcImg->height)); dstImg->nChannels =1; cvCopy(greyImg, dstImg); cvResetImageROI(dstImg); //载入边缘检测图像到目标图像 cvSetImageROI(dstImg, cvRect((srcImg->width) *2.0, 0, srcImg->width, srcImg->height)); dstImg->nChannels =1; cvCopy(cannyImg, dstImg); cvResetImageROI(dstImg); //--------------------------------------- cvNamedWindow("dstImg"); cvShowImage("dstImg", dstImg); cvWaitKey(0); cvReleaseImage(&srcImg); cvReleaseImage(&greyImg); cvReleaseImage(&cannyImg); cvReleaseImage(&dstImg); cvDestroyWindow("dstImg"); return0;}
http://www.cnblogs.com/CBDoctor/archive/2011/09/19/2180998.html
下面是几个知识点:
(1)路径的设置方式:通常情况下,需要把包含图片的文件夹保存到工程目录下,也就是保证和Debug在同一个根目录下面;
(2)cvSetImageROI函数和cvCopy函数的用法:
cvSetImageROI(IplImage*dst,cvRect(左边界,上边界,宽度,高度))。他的作用是把图像在图像dst中开辟出cvRect矩形框区域大小的内存空间,然后cvCopy(IplImage*src,IplImage*dst)函数会将源图像src复制到目标图像dst中。