threshold函数怎么用
时间: 2023-07-08 21:18:01 浏览: 131
threshold函数是OpenCV图像处理库中的一个函数,它用于对图像进行二值化处理。
threshold函数的语法如下:
```c++
void threshold(InputArray src, OutputArray dst, double thresh, double maxval, int type);
```
其中:
- src:输入图像
- dst:输出图像
- thresh:阈值,用于将像素值进行分类
- maxval:当像素值大于阈值时,所赋的值
- type:阈值处理的方法,包括THRESH_BINARY、THRESH_BINARY_INV、THRESH_TRUNC、THRESH_TOZERO和THRESH_TOZERO_INV等
以下是一个简单的示例:
```c++
#include <opencv2/opencv.hpp>
using namespace cv;
int main()
{
Mat image = imread("input.jpg", IMREAD_GRAYSCALE);
Mat binary;
threshold(image, binary, 150, 255, THRESH_BINARY);
imshow("Input Image", image);
imshow("Binary Image", binary);
waitKey(0);
return 0;
}
```
这个例子将读入一张灰度图像,然后使用阈值150对图像进行二值化处理,得到一个二值化图像。最后,将原图像和二值化图像显示出来。
阅读全文
相关推荐


















