博客
关于我
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/

    你可能感兴趣的文章
    Prometheus监控mysq数据库实战
    查看>>
    prometheus监控nginx实战
    查看>>
    Prometheus监控redis数据库实战
    查看>>
    Prometheus监控教程:使用Grafana展示主机基本信息
    查看>>
    pytorch中如何使用预训练词向量
    查看>>
    Prometheus监控教程:使用PromQL查询监控数据(上篇)
    查看>>
    Prometheus监控教程:使用PromQL查询监控数据(下篇)
    查看>>
    Pytorch中关于forward函数的理解与用法
    查看>>
    Prometheus监控教程:安装部署
    查看>>
    Prometheus监控教程:配置介绍
    查看>>
    Pytorch中tqdm进度条的使用
    查看>>
    Prometheus(2):SpringBoot 2.X集成Prometheus
    查看>>
    Promise 原理解析与实现(遵循Promise/A+规范)
    查看>>
    PyTorch:传递 numpy 数组进行权重初始化
    查看>>
    PyTorch-Tutorials【pytorch官方教程中英文详解】- 8 Save and Load Model
    查看>>
    promise.all是并发执行吗_攻破面试灵魂拷问,解读Java并发编程的艺术,本文带你深入l理解...
    查看>>
    PyTorch-Tutorials【pytorch官方教程中英文详解】- 7 Optimization
    查看>>
    promise总结
    查看>>
    Propel项目改为基于TensorFlow.js
    查看>>
    PyTorch-Tutorials【pytorch官方教程中英文详解】- 6 Autograd
    查看>>