opencv 阈值处理

#include <opencv2/opencv.hpp>

int main(void)
{
   IplImage *src_image = 0;
   IplImage *dst_image = 0;
   IplImage *dst_image_adaptive = 0;
   int c;
   int threshold_type;
   int thresh_val;
   int max_val;
   int adaptive_method;
   int block_size;
   int offset;
   
   src_image = cvLoadImage( "e:\\kankan\\baihe.jpg",0);
      
   
   dst_image = cvCreateImage(cvSize(src_image->width,src_image->height), IPL_DEPTH_8U, 1);
   cvNamedWindow( "Threshold", CV_WINDOW_AUTOSIZE );

 //  dst_image_adaptive = cvCreateImage(cvSize(src_image->width,src_image->height), IPL_DEPTH_8U, 1);
//   cvNamedWindow( "ThresholdAdaptive", CV_WINDOW_AUTOSIZE );

   threshold_type = CV_THRESH_BINARY;
   int threshold_typeBef = CV_THRESH_BINARY+1;
   cvCreateTrackbar( "threshold type", "Threshold", &threshold_type, 1, 0 );

   thresh_val = 100;
   int thresh_valBef = 0;
   cvCreateTrackbar( "thresh val", "Threshold", &thresh_val, 255, 0 );

   max_val = 100;
   int max_valBef = 0;
   cvCreateTrackbar( "max val", "Threshold", &max_val, 255, 0 );

 //  adaptive_method = CV_ADAPTIVE_THRESH_MEAN_C;
 //  int adaptive_methodBef = 1;
 //  cvCreateTrackbar( "adaptive method", "ThresholdAdaptive", &adaptive_method, 1, 0 );
      
/*   block_size = 1;
   int block_sizeBef = 0;
   cvCreateTrackbar( "block size", "ThresholdAdaptive", &block_size, 60, 0 );
         
   offset = 30;
   int offsetBef = 0;
   cvCreateTrackbar( "offset", "ThresholdAdaptive", &offset, 60, 0 );          */
            


   for(;;)
   {
      if((threshold_typeBef != threshold_type)    ||
         (thresh_valBef != thresh_val )          ||
         (max_valBef != max_val)   )
      {
      //   cvAdaptiveThreshold(src_image, dst_image_adaptive, (double)max_val, adaptive_method, 
          //              threshold_type, block_size*2+3, (double)(offset-30));
         
    //     cvShowImage("ThresholdAdaptive", dst_image_adaptive);


         if(max_val < thresh_val )
         {
            max_val = thresh_val;
         }
         cvThreshold(src_image, dst_image, (double)thresh_val, 
                  (double)max_val, threshold_type);
         cvShowImage("Threshold", dst_image);

         
         threshold_typeBef = threshold_type;
         thresh_valBef = thresh_val;
         max_valBef = max_val;
   //      adaptive_methodBef = adaptive_method;
  //       block_sizeBef = block_size;
  //       offsetBef = offset;

            
         //printf("The edge detection method is \n");
      }
      c = cvWaitKey(30);
      if( c == 'q' || c == 'Q' || (c & 255) == 27 || (c & 255) == 32 )
            break;
   }
   
   cvDestroyWindow( "Threshold" );//销毁窗口
//   cvDestroyWindow( "ThresholdAdaptive" );//销毁窗口
   cvReleaseImage( &src_image ); //释放图像
   cvReleaseImage( &dst_image ); //释放图像
 //  cvReleaseImage( &dst_image_adaptive ); //释放图像
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值