Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
c83044d4
Commit
c83044d4
authored
Feb 20, 2015
by
berak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix houghlines.py sample and tutorial
fix whitespace
parent
df57d038
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
22 deletions
+24
-22
py_houghlines.markdown
...tutorials/py_imgproc/py_houghlines/py_houghlines.markdown
+6
-6
houghlines.py
samples/python2/houghlines.py
+18
-16
No files found.
doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.markdown
View file @
c83044d4
...
...
@@ -59,7 +59,7 @@ denotes they are the parameters of possible lines in the image. (Image courtesy:

Hough Tranform in OpenCV
Hough Tran
s
form in OpenCV
=========================
Everything explained above is encapsulated in the OpenCV function,
\*\*
cv2.HoughLines()
\*\*
. It simply returns an array of :math:(rho,
...
...
@@ -78,7 +78,8 @@ gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
lines = cv2.HoughLines(edges,1,np.pi/180,200)
for rho,theta in lines
[
0
]
:
for line in lines:
rho,theta = line
[
0
]
a = np.cos(theta)
b = np.sin(theta)
x0 = a
*
rho
...
...
@@ -123,10 +124,9 @@ import numpy as np
img = cv2.imread('dave.jpg')
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray,50,150,apertureSize = 3)
minLineLength = 100
maxLineGap = 10
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
for x1,y1,x2,y2 in lines
[
0
]
:
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10)
for line in lines:
x1,y1,x2,y2 = line
[
0
]
cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imwrite('houghlines5.jpg',img)
...
...
samples/python2/houghlines.py
View file @
c83044d4
...
...
@@ -18,23 +18,25 @@ src = cv2.imread(fn)
dst
=
cv2
.
Canny
(
src
,
50
,
200
)
cdst
=
cv2
.
cvtColor
(
dst
,
cv2
.
COLOR_GRAY2BGR
)
# HoughLines()
# lines = cv2.HoughLines(dst, 1, math.pi/180.0, 50, np.array([]), 0, 0)
# a,b,c = lines.shape
# for i in range(b):
# rho = lines[0][i][0]
# theta = lines[0][i][1]
# a = math.cos(theta)
# b = math.sin(theta)
# x0, y0 = a*rho, b*rho
# pt1 = ( int(x0+1000*(-b)), int(y0+1000*(a)) )
# pt2 = ( int(x0-1000*(-b)), int(y0-1000*(a)) )
# cv2.line(cdst, pt1, pt2, (0, 0, 255), 3, cv2.LINE_AA)
if
True
:
# HoughLinesP
lines
=
cv2
.
HoughLinesP
(
dst
,
1
,
math
.
pi
/
180.0
,
40
,
np
.
array
([]),
50
,
10
)
a
,
b
,
c
=
lines
.
shape
for
i
in
range
(
a
):
cv2
.
line
(
cdst
,
(
lines
[
i
][
0
][
0
],
lines
[
i
][
0
][
1
]),
(
lines
[
i
][
0
][
2
],
lines
[
i
][
0
][
3
]),
(
0
,
0
,
255
),
3
,
cv2
.
LINE_AA
)
else
:
# HoughLines
lines
=
cv2
.
HoughLines
(
dst
,
1
,
math
.
pi
/
180.0
,
50
,
np
.
array
([]),
0
,
0
)
a
,
b
,
c
=
lines
.
shape
for
i
in
range
(
a
):
rho
=
lines
[
i
][
0
][
0
]
theta
=
lines
[
i
][
0
][
1
]
a
=
math
.
cos
(
theta
)
b
=
math
.
sin
(
theta
)
x0
,
y0
=
a
*
rho
,
b
*
rho
pt1
=
(
int
(
x0
+
1000
*
(
-
b
)),
int
(
y0
+
1000
*
(
a
))
)
pt2
=
(
int
(
x0
-
1000
*
(
-
b
)),
int
(
y0
-
1000
*
(
a
))
)
cv2
.
line
(
cdst
,
pt1
,
pt2
,
(
0
,
0
,
255
),
3
,
cv2
.
LINE_AA
)
lines
=
cv2
.
HoughLinesP
(
dst
,
1
,
math
.
pi
/
180.0
,
50
,
np
.
array
([]),
50
,
10
)
a
,
b
,
c
=
lines
.
shape
for
i
in
range
(
b
):
cv2
.
line
(
cdst
,
(
lines
[
0
][
i
][
0
],
lines
[
0
][
i
][
1
]),
(
lines
[
0
][
i
][
2
],
lines
[
0
][
i
][
3
]),
(
0
,
0
,
255
),
3
,
cv2
.
LINE_AA
)
cv2
.
imshow
(
"source"
,
src
)
cv2
.
imshow
(
"detected lines"
,
cdst
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment