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

    你可能感兴趣的文章
    npm install digital envelope routines::unsupported解决方法
    查看>>
    npm install 卡着不动的解决方法
    查看>>
    npm install 报错 EEXIST File exists 的解决方法
    查看>>
    npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
    查看>>
    npm install 报错 Failed to connect to github.com port 443 的解决方法
    查看>>
    npm install 报错 fatal: unable to connect to github.com 的解决方法
    查看>>
    npm install 报错 no such file or directory 的解决方法
    查看>>
    npm install 权限问题
    查看>>
    npm install报错,证书验证失败unable to get local issuer certificate
    查看>>
    npm install无法生成node_modules的解决方法
    查看>>
    npm install的--save和--save-dev使用说明
    查看>>
    npm node pm2相关问题
    查看>>
    npm run build 失败Compiler server unexpectedly exited with code: null and signal: SIGBUS
    查看>>
    npm run build报Cannot find module错误的解决方法
    查看>>
    npm run build部署到云服务器中的Nginx(图文配置)
    查看>>
    npm run dev 和npm dev、npm run start和npm start、npm run serve和npm serve等的区别
    查看>>
    npm run dev 报错PS ‘vite‘ 不是内部或外部命令,也不是可运行的程序或批处理文件。
    查看>>
    npm scripts 使用指南
    查看>>
    npm should be run outside of the node repl, in your normal shell
    查看>>
    npm start运行了什么
    查看>>