opencv几种常见的阈值分割方式

来源:互联网 发布:现在开淘宝店要钱吗 编辑:程序博客网 时间:2024/05/13 14:32

下面就介绍OpenCV中对图像进行二值化的关键函数——cvThreshold()

函数功能:采用Canny方法对图像进行边缘检测

函数原型:

void cvThreshold(

  const CvArrsrc,

  CvArrdst,

  double threshold,

  double max_value,

  int threshold_type

);

函数说明:

第一个参数表示输入图像,必须为单通道灰度图。

第二个参数表示输出的边缘图像,为单通道黑白图。

第三个参数表示阈值

第四个参数表示最大值。

第五个参数表示运算方法。

OpenCVimgproc\types_c.h中可以找到运算方法的定义。

/* Threshold types */

enum

{

    CV_THRESH_BINARY      =0,  /* value = value > threshold ? max_value : 0       */

    CV_THRESH_BINARY_INV  =1,  /* value = value > threshold ? 0 : max_value       */

    CV_THRESH_TRUNC       =2,  /* value = value > threshold ? threshold : value   */

    CV_THRESH_TOZERO      =3,  /* value = value > threshold ? value : 0           */

    CV_THRESH_TOZERO_INV  =4,  /* value = value > threshold ? 0 : value           */

    CV_THRESH_MASK        =7,

    CV_THRESH_OTSU        =8  /* use Otsu algorithm to choose the optimal threshold value; combine the flag with one of the above CV_THRESH_* values */

};

注释已经写的很清楚了,因此不再用中文来表达了。

0 0