blur & threshold
This commit is contained in:
18
Threshold/auto.cpp
Normal file
18
Threshold/auto.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include <opencv2/opencv.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
cv::Mat img = cv::imread("../img/2.jpg", cv::IMREAD_GRAYSCALE);
|
||||
if (img.empty()) return -1;
|
||||
|
||||
cv::Mat dst;
|
||||
// 注意:使用 THRESH_OTSU 时,输入的 thresh 参数 (0) 会被忽略
|
||||
// 它是通过 “标志位组合” 来实现的:cv::THRESH_BINARY | cv::THRESH_OTSU
|
||||
double otsuThresh = cv::threshold(img, dst, 0, 255, cv::THRESH_BINARY | cv::THRESH_OTSU);
|
||||
|
||||
std::cout << "Otsu 自动确定的阈值是: " << otsuThresh << std::endl;
|
||||
|
||||
cv::imshow("Otsu Threshold", dst);
|
||||
cv::waitKey(0);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user