在OpenCV中cvThreshold / threshold返回的double究竟是什么?

时间:2012-03-06 17:40:10

标签: opencv

我正在OpenCV中编写一个Android应用程序,并花了几个小时研究C示例中使用的一些函数http://www.shervinemami.info/blobs.html

cvThreshold函数在示例程序中使用,如此 -

cvThreshold(planeH, planeH, 18, UCHAR_MAX, CV_THRESH_BINARY_INV);
cvThreshold(planeS, planeS, 50, UCHAR_MAX, CV_THRESH_BINARY);
cvThreshold(planeV, planeV, 80, UCHAR_MAX, CV_THRESH_BINARY);

有5个参数。我在函数中找到的文档显示了相同的参数,但函数似乎返回了double而不是void。

参数是 -

cvThreshold(sourceImage, destinationImage, minThreshold, maxThreshold, 
            thresholdType);

据我所知(并记录在案),该函数根据所选的thresholdType检查源图像以查看哪些元素属于指定范围(最小和最大阈值之间),并将结果输出到目标图片。但我不知道为什么会返回双倍 ......

随Android版提供的文档包含在下面。

/**
 * Applies a fixed-level threshold to each array element.
 *
 * The function applies fixed-level thresholding to a single-channel array. The
 * function is typically used to get a bi-level (binary) image out of a
 * grayscale image ("compare" could be also used for this purpose) or for
 * removing a noise, that is, filtering out pixels with too small or too large
 * values. There are several types of thresholding supported by the function.
 * They are determined by "thresholdType" :
 *   * THRESH_BINARY
 *
 * dst(x,y) = maxVal if src(x,y) > thresh; 0 otherwise
 *
 *   * THRESH_BINARY_INV
 *
 * dst(x,y) = 0 if src(x,y) > thresh; maxVal otherwise
 *
 *   * THRESH_TRUNC
 *
 * dst(x,y) = threshold if src(x,y) > thresh; src(x,y) otherwise
 *
 *   * THRESH_TOZERO
 *
 * dst(x,y) = src(x,y) if src(x,y) > thresh; 0 otherwise
 *
 *   * THRESH_TOZERO_INV
 *
 * dst(x,y) = 0 if src(x,y) > thresh; src(x,y) otherwise
 *
 * Also, the special value "THRESH_OTSU" may be combined with one of the above
 * values. In this case, the function determines the optimal threshold value
 * using the Otsu's algorithm and uses it instead of the specified "thresh".
 * The function returns the computed threshold value.
 * Currently, the Otsu's method is implemented only for 8-bit images.
 *
 * @param src Source array (single-channel, 8-bit of 32-bit floating point).
 * @param dst Destination array of the same size and type as "src".
 * @param thresh Threshold value.
 * @param maxval a maxval
 * @param type a type
 *
 * @see <a href="http://opencv.itseez.com/modules/imgproc/doc/miscellaneous_transformations.html#threshold">org.opencv.imgproc.Imgproc.threshold</a>
 * @see org.opencv.imgproc.Imgproc.findContours
 * @see org.opencv.core.Core.max
 * @see org.opencv.imgproc.Imgproc.adaptiveThreshold
 * @see org.opencv.core.Core.compare
 * @see org.opencv.core.Core.min
 */

1 个答案:

答案 0 :(得分:5)

对于使用Otsu's method

的自动阈值模式THRESH_OTSU,它才真正有意义