public AdaptiveThresholdLayer(double maxValue, AdaptiveThresholdTypes adaptiveMethod, ThresholdTypes thresholdType, int blockSize, double c) { MaxValue = maxValue; AdaptiveMethod = adaptiveMethod; ThresholdType = thresholdType; BlockSize = blockSize; C = c; }
public Mat adaptiveThreshold(Mat img, double maxValue, AdaptiveThresholdTypes method, ThresholdTypes type, int blockSize, double delta) { var dst = new Mat(); cv2_native_api.imgproc_adaptiveThreshold(img.InputArray, dst.OutputArray, maxValue, (int)method, (int)type, blockSize, delta); return(dst); }
public override bool run() { object v; bool ret; try { v = getValue("method"); switch ((Method)v) { case Method.Threshold: threshold = (double)getValue("threshold"); maxvalue = (double)getValue("maxvalue"); thresholdType = (ThresholdTypes)getValue("thresholdType"); dst = src.Threshold(threshold, maxvalue, thresholdType); break; case Method.AdaptiveThreshold: maxvalue = (double)getValue("maxvalue"); adaptiveType = (AdaptiveThresholdTypes)getValue("adaptiveType"); thresholdType = (ThresholdTypes)getValue("thresholdType"); blocksize = (int)getValue("blocksize"); if (blocksize % 2 == 0) { blocksize++; } C = (double)getValue("C"); dst = src.AdaptiveThreshold(maxvalue, adaptiveType, thresholdType, blocksize, C); break; default: break; } ret = true; } catch (Exception ex) { throw ex; } return(ret); }
//自适应阈值分割函数封装 private Mat AdaptiveThreshold(Mat image, Mat grayImage, Mat binImage, AdaptiveThresholdTypes adaptiveThresholdTypes, ThresholdTypes thresholdTypes) { Cv2.CvtColor(image, grayImage, ColorConversionCodes.BGR2GRAY);//色彩空间转换 Cv2.AdaptiveThreshold(grayImage, binImage, 255, adaptiveThresholdTypes, thresholdTypes, 7, 1); return(binImage); }
/// <summary> /// Applies an adaptive threshold to an array. /// </summary> /// <param name="src">Source 8-bit single-channel image.</param> /// <param name="dst">Destination image of the same size and the same type as src .</param> /// <param name="maxValue">Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.</param> /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C .</param> /// <param name="thresholdType">Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV .</param> /// <param name="blockSize">Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.</param> /// <param name="c">Constant subtracted from the mean or weighted mean (see the details below). /// Normally, it is positive but may be zero or negative as well.</param> public static void AdaptiveThreshold(InputArray src, OutputArray dst, double maxValue, AdaptiveThresholdTypes adaptiveMethod, ThresholdTypes thresholdType, int blockSize, double c) { if (src == null) throw new ArgumentNullException(nameof(src)); if (dst == null) throw new ArgumentNullException(nameof(dst)); src.ThrowIfDisposed(); dst.ThrowIfNotReady(); NativeMethods.imgproc_adaptiveThreshold(src.CvPtr, dst.CvPtr, maxValue, (int)adaptiveMethod, (int)thresholdType, blockSize, c); GC.KeepAlive(src); dst.Fix(); }
/// <summary> /// Applies an adaptive threshold to an array. /// Source matrix must be 8-bit single-channel image. /// </summary> /// <param name="maxValue">Non-zero value assigned to the pixels for which the condition is satisfied. See the details below.</param> /// <param name="adaptiveMethod">Adaptive thresholding algorithm to use, ADAPTIVE_THRESH_MEAN_C or ADAPTIVE_THRESH_GAUSSIAN_C .</param> /// <param name="thresholdType">Thresholding type that must be either THRESH_BINARY or THRESH_BINARY_INV .</param> /// <param name="blockSize">Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.</param> /// <param name="c">Constant subtracted from the mean or weighted mean (see the details below). /// Normally, it is positive but may be zero or negative as well.</param> /// <returns>Destination image of the same size and the same type as src.</returns> public Mat AdaptiveThreshold(double maxValue, AdaptiveThresholdTypes adaptiveMethod, ThresholdTypes thresholdType, int blockSize, double c) { var dst = new Mat(); Cv2.AdaptiveThreshold(this, dst, maxValue, adaptiveMethod, thresholdType, blockSize, c); return dst; }