程序:

wKiom1PsYauAb2jkAAEI5gsfa_Q097.jpg

代码:

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
int GetCol(int argc,char** argv)
{
IplImage* src=cvLoadImage("e:\\picture\\4.jpg");
IplImage* dst1=cvCreateImage(cvSize(1,src->height),src->depth,src->nChannels);
cvZero(dst1);
IplImage* dst2=cvCreateImage(cvSize(20,src->height),src->depth,src->nChannels);
cvZero(dst2);
IplImage* dst3=cvCreateImage(cvSize(30,30),src->depth,src->nChannels);
cvZero(dst3);
cvGetCol(src,(CvMat*)dst1,10);  //获取第十列,注意这里并没有创建内存或者数据的复制,只是让dst1指向第十列
cvGetCols(src,(CvMat*)dst2,10,30);;
cvGetSubRect(src,(CvMat*)dst3,cvRect(10,10,30,30)); //获取图像的矩形区域
cvNamedWindow("src");
cvNamedWindow("dst1");
cvNamedWindow("dst2");
cvNamedWindow("dst3");
cvShowImage("src",src);
cvShowImage("dst1",dst1);
cvShowImage("dst2",dst2);
cvShowImage("dst3",dst3);
cvZero(dst2);            //由于只是让dst2指向源图像特定的列数,所以修改dst2也会修改原图像
cvNamedWindow("src2");
cvShowImage("src2",src);
cvWaitKey(0);
cvDestroyWindow("src");
cvDestroyWindow("dst1");
cvDestroyWindow("dst2");
cvDestroyWindow("dst3");
cvDestroyWindow("src2");
cvReleaseImage(&src);
cvReleaseImage(&dst1);
cvReleaseImage(&dst2);
cvReleaseImage(&dst3);
return 0;
}