enzoyang's recent timeline updates
enzoyang

enzoyang

V2EX member #171831, joined on 2016-05-05 16:47:08 +08:00
enzoyang's recent replies
应该是 detect_vertical_edges,代码里弄混了
谢谢大家的提示,我试验了一下,边缘检测加判断图中竖直的边缘应该够用了

```
def detect_horizontal_edges(cv_img) -> list:
"""找出图片中的竖线边界"""

if isinstance(cv_img, str):
cv_img = cv2.imread(cv_img)

# 转成灰度
gray_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2GRAY)
# 边缘检测
canny = cv2.Canny(gray_img, 20, 100)
# 加粗边缘
kernal = cv2.getStructuringElement(cv2.MORPH_RECT, (2, 2))
dilated = cv2.dilate(canny, kernal)

# 判断竖线
h, w = dilated.shape[0], dilated.shape[1]
threshold = int(h * 0.75)
edge_positions = []
for x in range(w):
white_dots = 0
for y in range(h):
if dilated[y, x] == 255:
white_dots += 1
if white_dots > threshold:
edge_positions.append(x)

return edge_positions
```
About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5759 Online   Highest 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 22ms · UTC 03:34 · PVG 11:34 · LAX 20:34 · JFK 23:34
♥ Do have faith in what you're doing.