gpt4 book ai didi

c++ - cv::adaptiveThreshold 中的断言失败(blockSize % 2 == 1 && blockSize > 1)

转载 作者:搜寻专家 更新时间:2023-10-31 00:13:21 39 4
gpt4 key购买 nike

我正在尝试做一个自适应阈值:

cv::Mat mat = cv::imread(inputFile);
cv::cvtColor(mat, mat, CV_BGR2GRAY);
cv::adaptiveThreshold(mat, mat, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 20, 0);
cv::imwrite(outputFile, mat);

但它失败并显示此消息:

OpenCV Error: Assertion failed (blockSize % 2 == 1 && blockSize > 1) in cv::adaptiveThreshold, file ..\..\..\..\opencv\modules\imgproc\src\thresh.cpp, line 797

问题是什么?

最佳答案

问题是我为 blockSize 设置了一个偶数值,而它只需要奇数值,所以将它从 20 更改为 21 修复了断言失败:

cv::adaptiveThreshold(mat, mat, 255, cv::ADAPTIVE_THRESH_MEAN_C, cv::THRESH_BINARY, 21, 0);

The docs有点提到它,但它们不是明确的,如果 blockSize 不是奇数,它将失败:

blockSize – Size of a pixel neighborhood that is used to calculate a threshold value for the pixel: 3, 5, 7, and so on.

如您所见,它没有说“如果 blockSize 不是奇数,它将失败”。

关于c++ - cv::adaptiveThreshold 中的断言失败(blockSize % 2 == 1 && blockSize > 1),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27268636/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com