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

    你可能感兴趣的文章
    notepad++最详情汇总
    查看>>
    notepad++正则表达式替换字符串详解
    查看>>
    notepad如何自动对齐_notepad++怎么自动排版
    查看>>
    Notes on Paul Irish's "Things I learned from the jQuery source" casts
    查看>>
    Notification 使用详解(很全
    查看>>
    NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
    查看>>
    NotImplementedError: Could not run torchvision::nms
    查看>>
    nova基于ubs机制扩展scheduler-filter
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    np.power的使用
    查看>>
    NPM 2FA双重认证的设置方法
    查看>>
    npm build报错Cannot find module ‘webpack/lib/rules/BasicEffectRulePlugin‘解决方法
    查看>>
    npm build报错Cannot find module ‘webpack‘解决方法
    查看>>
    npm ERR! ERESOLVE could not resolve报错
    查看>>
    npm ERR! fatal: unable to connect to github.com:
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near '...on":"0.10.3","direc to'
    查看>>
    npm ERR! Unexpected end of JSON input while parsing near ‘...“:“^1.2.0“,“vue-html-‘ npm ERR! A comp
    查看>>
    npm error Missing script: “server“npm errornpm error Did you mean this?npm error npm run serve
    查看>>