博客
关于我
OpenCV提供的各种阈值选项的实例(附完整代码)
阅读量:264 次
发布时间:2019-03-01

本文共 1114 字,大约阅读时间需要 3 分钟。

OpenCV提供了多种阈值选项,用户可以根据具体需求选择合适的阈值设置。以下是一些常见的阈值选项及其示例应用。

阈值选项分类

OpenCV中的阈值设置主要包括以下几种常用选项:

  • 简单阈值(Threshold Inverse Brightness-based):使用反亮度值进行阈值判断。
  • 高斯阈值(Gaussian Thresholding):基于高斯滤镜进行阈值计算。
  • 自适应阈值(Adaptive Thresholding):根据图像的局部或全局信息自动调整阈值。
  • 阈值设置示例

    以下是一个简单的OpenCV代码示例,展示如何设置常用阈值选项。

    #include "opencv2/imgproc.hpp"#include "opencv2/imgcodecs.hpp"#include "opencv2/highgui.hpp"#include 
    using namespace cv;
    // 简单阈值设置示例Mat src = imread("test_image.jpg");Mat gray;cvtColor(src, gray, COLOR_RGB2GRAY);// 简单阈值设置int threshold = 120; // 阈值值Mat binary_img(gray.size(), CV_GRAY2BINARY, threshold);// 高斯阈值设置double gamma = 0.5; // gamma值int threshold_g = threshold; // 阈值值threshold_g = threshold_g * gamma; // 调整阈值binary_img = 255 / (255 + threshold_g/2.0);// 自适应阈值设置int maxC = 5; // 局部区域大小int adaptive_threshold = 50; // 自适应阈值值binary_img = adaptiveThreshold(gray, maxC, adaptive_threshold, 5, 5);

    常用参数说明

    在使用OpenCV阈值设置时,以下参数常常需要调整:

    • threshold(阈值值):用于简单阈值设置,通常设置为0-255之间的值。
    • gamma(伽马值):用于高斯阈值,值通常在0.5-1.5之间。
    • adaptive_threshold(自适应阈值值):用于自适应阈值,值通常为11-30之间。
    • maxC(局部区域大小):用于自适应阈值,建议设置为5-10。

    通过合理设置这些参数,可以根据图像的亮度、对比度和噪声水平,获取更优的阈值结果。

    转载地址:http://prpx.baihongyu.com/

    你可能感兴趣的文章
    PyTorch 的 10 条顶级知识点
    查看>>
    PS辅助工具Assistor PS
    查看>>
    pt-archiver 归档历史数据及参数详解
    查看>>
    PyQt5学习笔记——信号与槽
    查看>>
    pyqt5教程11:绘制外观
    查看>>
    pyqt5教程12:拖放功能
    查看>>
    Pytest框架环境切换实战教程!赶快收藏
    查看>>
    python - 如何并行化python numpy中的总和计算?
    查看>>
    python - 将字符串中的日期与今天的日期进行比较
    查看>>
    python binascii.Error: Incorrect padding
    查看>>
    python ctypes库中动态链接库加载方式
    查看>>
    python cv2读取rtsp实时码流按时生成连续视频文件
    查看>>
    Python Dataframe Groupby Mean和Std
    查看>>
    python datetime笔记
    查看>>
    python day01
    查看>>
    python day10
    查看>>
    Python Discord Bot - python clear_reaction() 清除所有反应而不是特定反应
    查看>>
    python ETL工具 pyetl
    查看>>
    Python eval 函数说明
    查看>>
    python file
    查看>>