阈值函数测试

来源:互联网 发布:金百福软件使用步骤 编辑:程序博客网 时间:2024/05/02 21:21

#include"cv.h"

#include"highgui.h"

#include "stdio.h"

 

void fun(IplImage *srctemp,IplImage *dsttemp)

{

       //对单通道数组进行固定阈值分割

       cvThreshold( srctemp, dsttemp, 120.0, 255, CV_THRESH_BINARY );

       cvNamedWindow("dsttemp",1);

       cvShowImage("dsttemp",dsttemp);

       //自适应阈值操作

       cvAdaptiveThreshold(srctemp,dsttemp,256.0,CV_ADAPTIVE_THRESH_MEAN_C,CV_THRESH_BINARY,3,5);

}

 

int main(int argc,char *argv[])

{

       IplImage * src=0;

       IplImage * dst=0;

       IplImage * dsttemp=0;

       IplImage * srctemp=0;

 

       src=cvLoadImage("rice.png",1);

       cvNamedWindow("src",1);

       cvShowImage("src",src);

       printf("channels=%d,depth=%d/n",src->nChannels,src->depth);

      

       srctemp = cvCreateImage(cvGetSize(src),src->depth,1);

       dsttemp = cvCreateImage(cvGetSize(src),src->depth,1);

       dst = cvCreateImage(cvGetSize(src),src->depth,3);

 

       for(int i=1;i<=src->nChannels;i++)

       {

              cvSetImageCOI(src,i);

              cvSetImageCOI(dst,i);

              cvCopy(src,srctemp,NULL);

              fun(srctemp,dsttemp);

              cvCopy(dsttemp,dst,NULL);

       }

       //fun(src,dst);

 

       cvNamedWindow("dst",1);

       cvShowImage("dst",dst);

 

       cvWaitKey(0);

       return 0;

}

原创粉丝点击