python画粗线_OpenCV / Python中的粗线

I'm trying to find hough lines in an image using opencv in python.

My code is:

import cv2

import numpy as np

img = cv2.imread('DLMIA.png')

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

edges = cv2.Canny(gray,100,200,apertureSize = 3)

cv2.imshow('edges',edges)

cv2.waitKey(0)

minLineLength = 30

maxLineGap = 10

lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)

for x1,y1,x2,y2 in lines[0]:

cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imshow('hough',img)

cv2.waitKey(0)

The image I use is .

My resulted image is .

My code example is taken from here.

The resulted image is not the same as noted in the previous link. Any help please?

解决方案

I found the solution.

The code example only shows the first hough line.

In case you want to print all the hough lines on an image you have to print all lines.

This is the corrected code:

import cv2

import numpy as np

img = cv2.imread('dave.jpg')

gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

edges = cv2.Canny(gray,100,200,apertureSize = 3)

cv2.imshow('edges',edges)

cv2.waitKey(0)

minLineLength = 30

maxLineGap = 10

lines = cv2.HoughLinesP(edges,1,np.pi/180,15,minLineLength=minLineLength,maxLineGap=maxLineGap)

for x in range(0, len(lines)):

for x1,y1,x2,y2 in lines[x]:

cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)

cv2.imshow('hough',img)

cv2.waitKey(0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值