20 lines
498 B
C++
20 lines
498 B
C++
#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;
|
|
double thresh = 127;
|
|
double maxVal = 255;
|
|
|
|
// 简单阈值处理:二进制阈值
|
|
// 返回值是处理时使用的阈值
|
|
double ret = cv::threshold(img, dst, thresh, maxVal, cv::THRESH_BINARY);
|
|
|
|
cv::imshow("Simple Threshold", dst);
|
|
cv::waitKey(0);
|
|
return 0;
|
|
} |