概述

Canny边缘检测算子是John.F.Canny与1986年开发出来的一个多级边缘检测算法;边缘检测是计算机视觉中一个非常古老的问题,它涉及到检测图像中的边缘来确定目标的边界,从而分离感兴趣的目标。最流行的边缘检测技术之一是Canny边缘检测。

对最优边缘检测算法评价:

  • 好的检测:算法能够尽可能多的标识出图片中的实际边缘;
  • 好的定位:标识出的边缘要与实际图片中的实际边缘尽可能的接近;
  • 最小响应:图像中的边缘只能标识一次,并且可能存在的图像噪声不应该标识为边缘。

函数

void cv::Canny
(
	InputArray 	    image,
    OutputArray 	edges,
    double 	threshold1,
    double 	threshold2,
    int 	apertureSize = 3,
    bool 	L2gradient = false 
)		
image 源图像
edges 输出图像
threshold1 第一个滞后性阈值
threshold2 第二个滞后性阈值
apertureSize  Sobel算子的大小(默认值为3)
L2gradient  计算图像梯度幅度标志(默认值为False;如果为 True,则使用更精确的 L2 范数进行计算)

测试代码

#include "widget.h"
#include "ui_widget.h"

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

using namespace cv;

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //载入图像
    cv::Mat src = imread("C:/opencv/fruit.jpg");
    imshow("src",src);

    //边缘检测
    Mat dst;
    Canny(src,dst,200,220);

    //显示
    imshow("dst",dst);

}

Widget::~Widget()
{
    delete ui;
}

测试结果

参考

 Opencv中的Canny边缘检测

OpenCV 中的 Canny 边缘检测

GitHub 加速计划 / opencv31 / opencv
238
21
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
6950bedb Use Mat::total() in Darknet IO 7 小时前
105a7747 doc: update image codec configuration reference (add AVIF, fix JPEG XL) #28393 This PR updates the build configuration documentation to: - Add AVIF to the supported format list (it was missing). - Clarify that some codecs (AVIF, JPEG XL) do not support BUILD_* options because OpenCV does not bundle their source code. - Update the description to include "write" capabilities for these formats. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake 1 天前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐