Skip to content

Commit e11864f

Browse files
committed
update ch25
1 parent 9632fe7 commit e11864f

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

ch25-Hough直线变换/25.1-OpenCV中的霍夫变换-HoughLines.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
__author__ = 'play4fun'
33
"""
44
create time:15-10-25 上午11:42
5+
6+
cv2.HoughLines()。 返回值就是 ρ, θ 。
7+
ρ 的单位是像素 θ 的单位是弧度。
8+
第一个参数是一个二值化图像 所以在进行霍夫变换之前 先进行 二值化 或者
9+
Canny 缘检测。
10+
第二和第三个值分别代 ρ 和 θ 的精确度。
11+
第四个参数是阈值, 只有累加其中的值高于阈值时才被认为是一条直线
12+
也可以把它看成能检测到的直线的最短长度 以像素点为单位 。
513
"""
614

715
import cv2
@@ -32,4 +40,4 @@
3240
# cv2.imwrite('houghlines3.jpg',img)
3341
cv2.imshow("houghlines3.jpg", img)
3442
cv2.waitKey(0)
35-
cv2.destroyAllWindows()
43+
cv2.destroyAllWindows()

ch25-Hough直线变换/HoughLinesP.py renamed to ch25-Hough直线变换/25.2-Probabilistic-Hough-Transform-HoughLinesP.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
minLineLength = 100
1515
maxLineGap = 10
16+
1617
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 100, minLineLength, maxLineGap)
1718
print("Len of lines:", len(lines))
1819
print(lines)
1920

2021
for line in lines:
2122
x1, y1, x2, y2 = line[0]
2223
cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 2)
24+
2325
# cv2.imwrite('houghlines5.jpg',img)
2426
cv2.imshow("houghlines3.jpg", img)
2527
cv2.waitKey(0)

ch25-Hough直线变换/HoughLinesP_camera.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
import numpy as np
1313

1414
cap = cv2.VideoCapture(0)
15+
# ret = cap.set(3, 640)
16+
# ret = cap.set(4, 480)
17+
1518
# while (True):
16-
while (cap.isOpened()):
19+
while cap.isOpened():
1720
# Capture frame-by-frame
1821
ret, frame = cap.read()
1922
# img = cv2.imread('../data/sudoku.jpg')
@@ -23,14 +26,18 @@
2326
minLineLength = 100
2427
maxLineGap = 10
2528
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 100, minLineLength, maxLineGap)
29+
if lines is None:
30+
continue
2631
print("Len of lines:", len(lines))
2732
print(lines)
2833

2934
for line in lines:
3035
x1, y1, x2, y2 = line[0]
3136
cv2.line(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
37+
3238
# cv2.imwrite('houghlines5.jpg',img)
3339
cv2.imshow("houghlines3.jpg", frame)
40+
3441
if cv2.waitKey(1) == ord("q"):
3542
break
3643

0 commit comments

Comments
 (0)