cvCmp、cvSplit的使用
使用cvCmp()创建一个掩码。加载一个真实的图像。使用cvSplit()将图像分割成红、绿、蓝三个通道图像。
a.找到并显示绿图
b.克隆这个绿图(分别命名为clone1和clone2)
c.求出这个绿色平面的最大值和最小值
d.将clone1的所有元素赋值为thresh=(unsigned char)((最大值-最小值)/2.0)
e.将clone1所有元素赋值为0,调用函数cvCmp(green_image,clone1,clone2,CV_CMP_GE)
f.最后,使用cvSubs(green_image,thresh/2,green_image,clone2)函数并显示结果
1 #include "cv.h" 2 #include "highgui.h" 3 4 int main(int argc, char** argv) 5 { 6 IplImage *img; 7 IplImage *clone1,*clone2; 8 9 img = cvLoadImage("lena.jpg",-1); 10 IplImage* dst = cvCreateImage(cvGetSize(img),img->depth,1); 11 cvSplit( img, 0, dst, 0, 0 ); 12 cvNamedWindow( "Green", CV_WINDOW_AUTOSIZE ); 13 cvShowImage( "Green", dst ); 14 15 clone1 = cvCloneImage(dst); 16 clone2 = cvCloneImage(dst); 17 18 double max,min; 19 cvMinMaxLoc(dst,&min,&max); 20 21 double thresh = (max-min)/2; 22 cvSet(clone1,cvScalar(thresh)); 23 24 cvZero(clone2); 25 cvCmp(dst,clone1,clone2,CV_CMP_GE); 26 cvSubS(dst,cvScalar(thresh/2),dst,clone2); 27 28 cvNamedWindow( "OpenCVTest6", CV_WINDOW_AUTOSIZE ); 29 cvShowImage( "OpenCVTest6", dst ); 30 cvWaitKey(); 31 cvDestroyWindow("Green"); 32 cvDestroyWindow("OpenCVTest6"); 33 cvReleaseImage(&dst); 34 35 return 0; 36 }