从OpenCV Canny边缘检测器获取角度 [英] Get angle from OpenCV Canny edge detector

查看:172
本文介绍了从OpenCV Canny边缘检测器获取角度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用OpenCV的Canny边缘检测器,例如概述的问题.例如:

I want to use OpenCV's Canny edge detector, such as is outlined in this question. For example:

cv::Canny(image,contours,10,350); 

但是,我不仅希望获得最终的阈值图像,而且还希望获得每个像素处检测到的边缘角度.这在OpenCV中可能吗?

However, I wish to not only get the final thresholded image out, but I also wish to get the detected edge angle at each pixel. Is this possible in OpenCV?

推荐答案

canny不能直接为您提供此功能. 但是,您可以通过canny()内部使用的Sobel变换来计算角度.

canny doesn't give you this directly. However, you can calculate the angle from the Sobel transform, which is used internally in canny().

伪代码:

    cv::Canny(image,contours,10,350);
    cv::Sobel(image, dx, CV_64F, 1, 0, 3, 1, 0, cv::BORDER_REPLICATE);
    cv::Sobel(image, dy, CV_64F, 0, 1, 3, 1, 0, cv::BORDER_REPLICATE);

    cv::Mat angle(image.size(), CV_64F)

    foreach (i,j) such that contours[i, j] > 0
    {
        angle[i, j] = atan2(dy[i,j], dx[i , j])
    }

这篇关于从OpenCV Canny边缘检测器获取角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆