Skip to content

Commit 9632fe7

Browse files
committed
Revert "Revert "up 13""
This reverts commit 9866848.
1 parent 9866848 commit 9632fe7

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# edges = cv2.Canny(gray,50,150,apertureSize = 3)
1313
edges = cv2.Canny(gray, 10, 50, apertureSize=3)
1414
cv2.imshow("edges", edges)
15+
1516
lines = cv2.HoughLines(edges, 1, np.pi / 180, 200)
1617
print("Len of lines:", len(lines))
1718
# print lines
@@ -31,3 +32,4 @@
3132
# cv2.imwrite('houghlines3.jpg',img)
3233
cv2.imshow("houghlines3.jpg", img)
3334
cv2.waitKey(0)
35+
cv2.destroyAllWindows()

官方samples/color_histogram.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,32 @@
1919

2020
if __name__ == '__main__':
2121

22+
# 构建 HSV颜色地图
2223
hsv_map = np.zeros((180, 256, 3), np.uint8)
24+
# np.indices 可以 回由数组索引构建的新数组。 例如 np.indices 3,2 其中 3,2 为原来数组的维度 和列。 回值 先看 入的参数有几维 3,2 有 2 维 所以从 出的结果应 是 [[a],[b]], 其中包含两个 3 2 列数组。 第二看每一维的大小 第一维为 3, 所以 a 中的值就 0 到 2 最大索引数 a 中的每一个值就是它的 索引 同样的方法得到 b 列索引
25+
# 结果就是
26+
# array([[[0, 0],
27+
# [1, 1],
28+
# [2, 2]],
29+
# [[0, 1],
30+
# [0, 1],
31+
# [0, 1]]])
2332
h, s = np.indices(hsv_map.shape[:2])
24-
hsv_map[:,:,0] = h
25-
hsv_map[:,:,1] = s
26-
hsv_map[:,:,2] = 255
33+
hsv_map[:, :, 0] = h
34+
hsv_map[:, :, 1] = s
35+
hsv_map[:, :, 2] = 255
2736
hsv_map = cv2.cvtColor(hsv_map, cv2.COLOR_HSV2BGR)
2837
cv2.imshow('hsv_map', hsv_map)
2938

3039
cv2.namedWindow('hist', 0)
3140
hist_scale = 10
3241

42+
3343
def set_scale(val):
3444
global hist_scale
3545
hist_scale = val
46+
47+
3648
cv2.createTrackbar('scale', 'hist', hist_scale, 32, set_scale)
3749

3850
try:
@@ -44,19 +56,21 @@ def set_scale(val):
4456
while True:
4557
flag, frame = cam.read()
4658
cv2.imshow('camera', frame)
47-
59+
# 图像 字塔
60+
# 图像 字塔 低分 率 但不会对直方图有太大影响。
61+
# 但 种低分 率 可以很好抑制噪声 从而去 孤立的小点对直方图的影响
4862
small = cv2.pyrDown(frame)
4963

5064
hsv = cv2.cvtColor(small, cv2.COLOR_BGR2HSV)
51-
dark = hsv[...,2] < 32
65+
dark = hsv[..., 2] < 32
5266
hsv[dark] = 0
5367
h = cv2.calcHist([hsv], [0, 1], None, [180, 256], [0, 180, 0, 256])
5468

55-
h = np.clip(h*0.005*hist_scale, 0, 1)
56-
vis = hsv_map*h[:,:,np.newaxis] / 255.0
69+
h = np.clip(h * 0.005 * hist_scale, 0, 1)
70+
vis = hsv_map * h[:, :, np.newaxis] / 255.0
5771
cv2.imshow('hist', vis)
5872

5973
ch = cv2.waitKey(1)
60-
if ch == 27:
74+
if ch == ord('q'):
6175
break
6276
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)