边界填充 cvCopyMakeBorder

核心函数:cvCopyMakeBorder

程序:

wKioL1PsLkXxBITUAAE36zLbFfU065.jpg

代码:

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <iostream>
int CopyMakeBorder(int argc,char** argv)
{
IplImage* src=cvLoadImage("e:\\picture\\4.jpg");
IplImage* dst1=cvCreateImage(cvSize(src->width+40,src->height+40),src->depth,src->nChannels);
IplImage* dst2=cvCreateImage(cvSize(src->width+40,src->height+40),src->depth,src->nChannels);
cvZero(dst1);
cvZero(dst2);
cvCopyMakeBorder(src,dst1,cvPoint(20,20),IPL_BORDER_REPLICATE); //用边界像素的值填充,replicate为复制,原图放在目标图像作为为(20,20)的位置
cvCopyMakeBorder(src,dst2,cvPoint(20,20),IPL_BORDER_CONSTANT,cvScalar(0,0,255)); //用固定指定像素填充,constant为不变的,恒定的
cvNamedWindow("src");
cvNamedWindow("dst1");
cvNamedWindow("dst2");
cvShowImage("src",src);
cvShowImage("dst1",dst1);
cvShowImage("dst2",dst2);
cvWaitKey(0);
cvDestroyWindow("src");
cvDestroyWindow("dst1");
cvDestroyWindow("dst2");
cvReleaseImage(&src);
cvReleaseImage(&dst1);
cvReleaseImage(&dst2);
return 0;
}


你可能感兴趣的:(opencv,边界填充)