图像截取:
IplImage *src1 = cvGetImage(cvGetSubRect(src, cvCreateMatHeader(width,height, CV_8UC1), cvRect(pointX, pointY, width,height)), cvCreateImageHeader(cvSize(width,height), 8, 1));//截取起始点:(pointX, pointY),截取宽度:width,截取长度:height
图像合并:
//将图像img1,img2()合并为img,
IplImage* img=cvCreateImage(cvSize(img1->width+img2->width,img1->height+img2->height),img1->depth,img1->channels);
CvRect rect=cvRect(0,0,img1->width,img1->height);
cvSetImageROI(img,rect);//设置图像感兴趣区域
cvCopy(img1,img);
cvResetImageROI(img);
rect=cvRect(img1->width,0,img2->width,img2->height);
cvSetImageROI(img,rect);
cvCopy(img2,img);
cvResetImageROI(img);
图像反色:
cvXorS(img, cvScalarAll(255), img);
图像求canny边缘:
IplImage* src;
src=cvLoadImage(“路径”,1);//读取彩色图
//-------canny
IplImage* dst = cvCreateImage( cvGetSize(src), 8, 1 );
IplImage* src1=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,1);
cvCvtColor(src, src1, CV_BGR2GRAY); //把src转换成灰度图像保存在src1中,注意进行边缘检测一定要换成灰度图
cvCanny( src1, dst, 20,200, 3 );//参数50,200的灰度变换
ShowImage(dst, IDC_STATIC_PIC);
图像二值化:
IplImage* src;
src=cvLoadImage(“路径”,1);//读取彩色图
IplImage* dst = cvCreateImage( cvGetSize(src), 8, 1 );
IplImage* src1=cvCreateImage(cvSize(src->width,src->height),IPL_DEPTH_8U,1);
cvCvtColor(src, src1, CV_BGR2GRAY); //把src转换成灰度图像保存在src1中
cvThreshold( src1,dst,100, 255, CV_THRESH_BINARY );//二值化:
ShowImage(dst, IDC_STATIC_PIC);