本文整理了Java中org.opencv.imgproc.Imgproc.adaptiveThreshold()
方法的一些代码示例,展示了Imgproc.adaptiveThreshold()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Imgproc.adaptiveThreshold()
方法的具体详情如下:
包路径:org.opencv.imgproc.Imgproc
类名称:Imgproc
方法名:adaptiveThreshold
[英]Applies an adaptive threshold to an array.
The function transforms a grayscale image to a binary image according to the formulae:
dst(x,y) = maxValue if src(x,y) > T(x,y); 0 otherwise
dst(x,y) = 0 if src(x,y) > T(x,y); maxValue otherwise
where T(x,y) is a threshold calculated individually for each pixel.
ADAPTIVE_THRESH_MEAN_C
, the threshold value T(x,y) is a mean of the blockSize x blockSize neighborhood of (x, y) minus C
.ADAPTIVE_THRESH_GAUSSIAN_C
, the threshold value T(x, y) is a weighted sum (cross-correlation with a Gaussian window) of the blockSize x blockSize neighborhood of (x, y) minus C
. The default sigma (standard deviation) is used for the specified blockSize
. See "getGaussianKernel".The function can process the image in-place.
[中]将自适应阈值应用于阵列。
该函数根据以下公式将灰度图像转换为二值图像:
THRESH_二进制
如果src(x,y)>T(x,y),则dst(x,y)=最大值;否则为0
阈值二元变量
如果src(x,y)>T(x,y),则dst(x,y)=0;否则为最大值
其中T(x,y)是为每个像素单独计算的阈值。
对于方法ADAPTIVE_THRESH_MEAN_C
,阈值T(x,y)是(x,y)的blockSize x blockSize邻域减去C
的平均值。
对于方法ADAPTIVE_THRESH_GAUSSIAN_C
,阈值T(x,y)是(x,y)的blockSize x blockSize邻域减去[$3$]的加权和(与高斯窗口的互相关)。默认西格玛(标准偏差)用于指定的blockSize
。见“getGaussianKernel”。
该功能可以就地处理图像。
代码示例来源:origin: openpnp/openpnp
public static Mat thresholdAdaptive(Mat mat, boolean invert) {
Imgproc.adaptiveThreshold(mat, mat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,
invert ? Imgproc.THRESH_BINARY_INV : Imgproc.THRESH_BINARY, 3, 5);
return mat;
}
代码示例来源:origin: openpnp/openpnp
public FluentCv thresholdAdaptive(boolean invert, String... tag) {
Imgproc.adaptiveThreshold(mat, mat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,
invert ? Imgproc.THRESH_BINARY_INV : Imgproc.THRESH_BINARY, 3, 5);
return store(mat, tag);
}
代码示例来源:origin: hschott/Camdroid
protected void execute() {
Mat gray = gray();
Imgproc.adaptiveThreshold(gray, out, 255,
Imgproc.THRESH_BINARY_INV, Imgproc.ADAPTIVE_THRESH_MEAN_C,
blocksize, reduction);
}
代码示例来源:origin: JavaOpenCVBook/code
protected void processOperation() {
if(adaptiveMeanString.equals(thresholdMode)){
Imgproc.adaptiveThreshold(originalImage, image, maxval, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, blockSize, constantC);
}
else if(noneString.equals(thresholdMode)){
image = originalImage.clone();
}
else{
Imgproc.threshold(originalImage, image, level, maxval, modeMap.get(thresholdMode));
}
updateView(image);
}
代码示例来源:origin: openpnp/openpnp
@Override
public Result process(CvPipeline pipeline) throws Exception {
Mat mat = pipeline.getWorkingImage();
Imgproc.adaptiveThreshold(mat, mat, 255, adaptiveMethod.getCode(), invert ? Imgproc.THRESH_BINARY_INV : Imgproc.THRESH_BINARY, blockSize, cParm);
return null;
}
}
代码示例来源:origin: hschott/Camdroid
protected void execute() {
out = gray();
Imgproc.equalizeHist(out, out);
Core.normalize(out, out, min, max, Core.NORM_MINMAX);
Imgproc.adaptiveThreshold(out, out, 255, Imgproc.THRESH_BINARY,
Imgproc.ADAPTIVE_THRESH_MEAN_C, blocksize, reduction);
byte[] data = new byte[(int) out.total()];
out.get(0, 0, data);
this.tessBaseAPI.setImage(data, out.width(), out.height(),
out.channels(), (int) out.step1());
String utf8Text = this.tessBaseAPI.getUTF8Text();
int score = this.tessBaseAPI.meanConfidence();
this.tessBaseAPI.clear();
if (score >= SIMPLETEXT_MIN_SCORE && utf8Text.length() > 0) {
simpleText = utf8Text;
} else {
simpleText = new String();
}
}
内容来源于网络,如有侵权,请联系作者删除!