python canny 保留指定区域的轮廓线_从Canny边缘检测中提取线条

In openCV after applying canny edge detection I'd like to further process the result (show only horizontal lines, remove short lines, etc..). But the result of canny is just another image. I'd like to get an array of lines describing the detected edges

I'm aware of the famous Hough Line Transform, but the result is not always good, that's why I'd like to manually process canny result.

input:

output canny only:

output canny then Hough line transform

This is Hough line transform result(red lines) for detecting edges of stairs. 4th line from below is not detected correctly, although canny edge detected an edge.

Any idea how to extract edges from canny image?

解决方案

A few things you can try to improve your results:

Apply a Region of Interest

Your image looks to have some bordering window effects. I removed them with a region of interest resulting in an image that looks like this (I tweaked it until it looked right, but if you're using some kind of kernel operator it's window size probably better defines this ROI):

Use standard Hough transform

It also seems you're using the probabilistic Hough transform. So, you're only getting line segments instead of an interpolated line. Consider using the standard transform to get the full theoretical line (rho, theta). Doing this I got an image like shown below:

Here is a code snippet I used to generate the lines (from Python interface):

(mu, sigma) = cv2.meanStdDev(stairs8u)

edges = cv2.Canny(stairs8u, mu - sigma, mu + sigma)

lines = cv2.HoughLines(edges, 1, pi / 180, 70)

Filter lines based on angle

You can probably filter out poor lines by taking the most frequently occurring line angles, and throwing away outliers. This should narrow it down to the most visible steps.

Hope that helps!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值