OpenCV中如何在没有Sobel滤波器的情况下过滤线路

发布于 2024-12-05 17:33:17 字数 927 浏览 0 评论 0原文

我正在尝试仅使用线性滤波器来检测线条。我的第一次尝试是像这样旋转内核,但行不通:

kernel = zeros((13,13))
kernel60 = zeros((13,13))

kernel[4] = [0,0,0,0,-1,-1,-1,-1,-1,0,0,0,0]
#kernel[5] = [0,0,0,0,0]
kernel[6] = [0,0,0,0,2,2,2,2,2,0,0,0,0]
#kernel[7] = [0,0,0,0,0]
kernel[8] = [0,0,0,0,-1,-1,-1,-1,-1,0,0,0,0]

rotate60 = zeros((2,3))
GetRotationMatrix2D((6,6),60,1, rotate60)
WarpAffine(kernel,kernel60,rotate60,CV_WARP_FILL_OUTLIERS, ScalarAll(0))

之后我准备了一个内核,它是两个 Sobel 内核(可操纵滤波器)的线性组合。这可行,但我最好喜欢非索贝尔内核,类似于第一次尝试。索贝尔内核有什么替代品吗?

Sobel Kernel组合:

kernel_x[0] = [-1,0,+1]
kernel_x[1] = [-1,0,+1]
kernel_x[2] = [-1,0,+1]

kernel_y[0] = [-1,-1,-1]
kernel_y[1] = [0,0,0]
kernel_y[2] = [+1,+1,+1]

normal_theta = radians(-30)
kernel = multiply(cos(theta),kernel_x) + multiply(sin(theta),kernel_y)

然后过滤:

Filter2D(src,dst,kernel)

我在Windows机器中使用Python和numpy。

I'm trying to detect lines just with linear filters. My first try was rotate a kernel like this but wouldn't work:

kernel = zeros((13,13))
kernel60 = zeros((13,13))

kernel[4] = [0,0,0,0,-1,-1,-1,-1,-1,0,0,0,0]
#kernel[5] = [0,0,0,0,0]
kernel[6] = [0,0,0,0,2,2,2,2,2,0,0,0,0]
#kernel[7] = [0,0,0,0,0]
kernel[8] = [0,0,0,0,-1,-1,-1,-1,-1,0,0,0,0]

rotate60 = zeros((2,3))
GetRotationMatrix2D((6,6),60,1, rotate60)
WarpAffine(kernel,kernel60,rotate60,CV_WARP_FILL_OUTLIERS, ScalarAll(0))

After that I prepared a kernel that's a linear combination from two Sobel kernels (steerable filters). This works but I would better like a non-sobel kernel, similar to the first try. Any alternative to the sobel kernels?

Sobel Kernel combination:

kernel_x[0] = [-1,0,+1]
kernel_x[1] = [-1,0,+1]
kernel_x[2] = [-1,0,+1]

kernel_y[0] = [-1,-1,-1]
kernel_y[1] = [0,0,0]
kernel_y[2] = [+1,+1,+1]

normal_theta = radians(-30)
kernel = multiply(cos(theta),kernel_x) + multiply(sin(theta),kernel_y)

Then filtering:

Filter2D(src,dst,kernel)

I use Python and numpy in a Windows machine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

享受孤独 2024-12-12 17:33:17

您可以使用 Canny 算法进行边缘检测(无论如何都使用 Sobel),使用霍夫变换进行直线检测。在 Canny 之前执行模糊可以帮助消除异常线。这是经典的方法。您可以使用 OpenCV 来实现这两个部分。

请参阅以下内容:

http://en.wikipedia.org/wiki/Hough_transform

http://en.wikipedia.org/wiki/Canny_edge_detector

以下是 OpenCV 实现的文档:

请参阅 cvHoughLines* 函数,其中有示例代码

You can use Canny algorithm for edge detection (which uses Sobel anyway) and Hough transform for line detection. Performing blur before Canny can help eliminate outlier lines. This is the classic approach. You can use OpenCV that implements both parts.

See the following:

http://en.wikipedia.org/wiki/Hough_transform

http://en.wikipedia.org/wiki/Canny_edge_detector

Here is the documentation for OpenCV implementation:
http://opencv.willowgarage.com/documentation/cpp/imgproc_feature_detection.html

see the cvHoughLines* functions there are sample code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文