Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f5e6d58

Browse files
committed
fix to ch20
1 parent 9798606 commit f5e6d58

File tree

12 files changed

+26
-22
lines changed

12 files changed

+26
-22
lines changed
File renamed without changes.

‎ch13-颜色空间转换/13.VideoCapture_blue_object.py‎ renamed to ‎ch13-颜色空间转换/2.物体跟踪_blue_object.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,34 @@
1818
'''
1919

2020
cap = cv2.VideoCapture(0)
21+
ret = cap.set(3, 640)
22+
ret = cap.set(4, 480)
2123
while True:
2224
# 获取每一帧
2325
ret, frame = cap.read()
2426
# 换到 HSV
2527
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
2628
# 定蓝色的阈值
27-
# lower_blue = np.array([110, 50, 50])
28-
# upper_blue = np.array([130, 255, 255])
29+
lower_blue = np.array([110, 50, 50])
30+
upper_blue = np.array([130, 255, 255])
2931

3032
# 黑色
31-
lower_black = np.array([0, 0, 0])
32-
upper_black = np.array([180, 255, 30])
33+
# lower_black = np.array([0, 0, 0])
34+
# upper_black = np.array([180, 255, 30])
3335

3436
# 根据阈值构建掩模
35-
# mask = cv2.inRange(hsv, lower_blue, upper_blue)
36-
mask = cv2.inRange(hsv, lower_black, upper_black)
37+
mask = cv2.inRange(hsv, lower_blue, upper_blue)
38+
# mask = cv2.inRange(hsv, lower_black, upper_black)
3739
# 对原图像和掩模位运算
3840
res = cv2.bitwise_and(frame, frame, mask=mask)
3941

4042
# 显示图像
4143
cv2.imshow('frame', frame)
4244
cv2.imshow('mask', mask)
4345
cv2.imshow('res', res)
44-
k = cv2.waitKey(0) # & 0xFF
45-
if k == 27:
46+
47+
k = cv2.waitKey(1) # & 0xFF
48+
if k == ord('q'):
4649
break
4750
# 关闭窗口
4851
cv2.destroyAllWindows()
49-

‎ch14-几何变换/14.resize.py‎ renamed to ‎ch14-几何变换/14.1.扩展缩放resize.py‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,11 @@
2020

2121
# OR
2222
# 我们直接设置输出图像的尺寸 所以不用设置缩放因子
23-
height, width = img.shape[:2]
24-
res = cv2.resize(img, (2 * width, 2 * height), interpolation=cv2.INTER_CUBIC)
23+
# height, width = img.shape[:2]
24+
# res = cv2.resize(img, (2 * width, 2 * height), interpolation=cv2.INTER_CUBIC)
2525

26-
while True:
27-
cv2.imshow('resize', res)
28-
cv2.imshow('src img', img)
26+
cv2.imshow('resize', res)
27+
cv2.imshow('src img', img)
2928

30-
key = cv2.waitKey(1)
31-
if key == ord("q"):
32-
break
29+
cv2.waitKey(0)
3330
cv2.destroyAllWindows()

‎ch14-几何变换/14.2平移.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import numpy as np
1414

1515
cap = cv2.VideoCapture(0)
16+
ret = cap.set(3, 640)
17+
ret = cap.set(4, 480)
1618
while True:
1719
# 获取每一帧
1820
ret, frame = cap.read()
@@ -32,7 +34,7 @@
3234
cv2.imshow('mask', mask)
3335
cv2.imshow('res', res)
3436

35-
k = cv2.waitKey(0) # & 0xFF
37+
k = cv2.waitKey(1) # & 0xFF
3638
if k == ord('q'):
3739
break
3840
# 关 窗口
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

‎ch16-图像平衡/图像模糊-平均.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'''
2020
现在把卷积核换成 斯核 简单来 方框不变 将原来每个方框的值是 相等的 现在 的值是符合 斯分布的 方框中心的值最大 其余方框根据 离中心元素的 离 减 构成一个 斯小山包。原来的求平均数现在变成求 加权平均数 全就是方框 的值 。
2121
'''
22-
# 0 是指根据窗口大小 5,5 来计算高斯函数标准差
22+
# 0 是指根据窗口大小 (5,5) 来计算高斯函数标准差
2323
blur = cv2.GaussianBlur(img, (5, 5), 0) # 高斯模糊
2424

2525
'''
@@ -43,10 +43,11 @@
4343
因为边界处的灰度值变化比较大。
4444
'''
4545

46+
#16.4 双边滤波
4647
# cv2.bilateralFilter(src, d, sigmaColor, sigmaSpace)
4748
# d – Diameter of each pixel neighborhood that is used during filtering. # If it is non-positive, it is computed from sigmaSpace
4849
# 9 域直径 两个 75 分别是空 斯函数标准差 灰度值相似性 斯函数标准差
49-
blur = cv2.bilateralFilter(img, 9, 75, 75)
50+
# blur = cv2.bilateralFilter(img, 9, 75, 75)
5051

5152
plt.subplot(121), plt.imshow(img), plt.title('Original')
5253
plt.xticks([]), plt.yticks([])

‎ch18-图像梯度/一个重要的事.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import numpy as np
2323
from matplotlib import pyplot as plt
2424

25-
img = cv2.imread('../data/box.png', 0)
25+
img = cv2.imread('../data/box.jpg', 0)
2626

2727
# Output dtype = cv2.CV_8U
2828
sobelx8u = cv2.Sobel(img, cv2.CV_8U, 1, 0, ksize=5)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /