Skip to content

Commit

Permalink
fix to ch20
Browse files Browse the repository at this point in the history
  • Loading branch information
makelove committed Jul 14, 2017
1 parent 9798606 commit f5e6d58
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 22 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,34 @@
'''

cap = cv2.VideoCapture(0)
ret = cap.set(3, 640)
ret = cap.set(4, 480)
while True:
# 获取每一帧
ret, frame = cap.read()
# 换到 HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# 定蓝色的阈值
# lower_blue = np.array([110, 50, 50])
# upper_blue = np.array([130, 255, 255])
lower_blue = np.array([110, 50, 50])
upper_blue = np.array([130, 255, 255])

# 黑色
lower_black = np.array([0, 0, 0])
upper_black = np.array([180, 255, 30])
# lower_black = np.array([0, 0, 0])
# upper_black = np.array([180, 255, 30])

# 根据阈值构建掩模
# mask = cv2.inRange(hsv, lower_blue, upper_blue)
mask = cv2.inRange(hsv, lower_black, upper_black)
mask = cv2.inRange(hsv, lower_blue, upper_blue)
# mask = cv2.inRange(hsv, lower_black, upper_black)
# 对原图像和掩模位运算
res = cv2.bitwise_and(frame, frame, mask=mask)

# 显示图像
cv2.imshow('frame', frame)
cv2.imshow('mask', mask)
cv2.imshow('res', res)
k = cv2.waitKey(0) # & 0xFF
if k == 27:

k = cv2.waitKey(1) # & 0xFF
if k == ord('q'):
break
# 关闭窗口
cv2.destroyAllWindows()

Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@

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

while True:
cv2.imshow('resize', res)
cv2.imshow('src img', img)
cv2.imshow('resize', res)
cv2.imshow('src img', img)

key = cv2.waitKey(1)
if key == ord("q"):
break
cv2.waitKey(0)
cv2.destroyAllWindows()
4 changes: 3 additions & 1 deletion ch14-几何变换/14.2平移.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import numpy as np

cap = cv2.VideoCapture(0)
ret = cap.set(3, 640)
ret = cap.set(4, 480)
while True:
# 获取每一帧
ret, frame = cap.read()
Expand All @@ -32,7 +34,7 @@
cv2.imshow('mask', mask)
cv2.imshow('res', res)

k = cv2.waitKey(0) # & 0xFF
k = cv2.waitKey(1) # & 0xFF
if k == ord('q'):
break
# 关 窗口
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions ch16-图像平衡/图像模糊-平均.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'''
现在把卷积核换成 斯核 简单来 方框不变 将原来每个方框的值是 相等的 现在 的值是符合 斯分布的 方框中心的值最大 其余方框根据 离中心元素的 离 减 构成一个 斯小山包。原来的求平均数现在变成求 加权平均数 全就是方框 的值 。
'''
# 0 是指根据窗口大小 5,5 来计算高斯函数标准差
# 0 是指根据窗口大小 (5,5) 来计算高斯函数标准差
blur = cv2.GaussianBlur(img, (5, 5), 0) # 高斯模糊

'''
Expand All @@ -43,10 +43,11 @@
因为边界处的灰度值变化比较大。
'''

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

plt.subplot(121), plt.imshow(img), plt.title('Original')
plt.xticks([]), plt.yticks([])
Expand Down
2 changes: 1 addition & 1 deletion ch18-图像梯度/一个重要的事.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('../data/box.png', 0)
img = cv2.imread('../data/box.jpg', 0)

# Output dtype = cv2.CV_8U
sobelx8u = cv2.Sobel(img, cv2.CV_8U, 1, 0, ksize=5)
Expand Down
2 changes: 1 addition & 1 deletion ch19-Canny边缘检测/19.Canny.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('../data/messi5.jpg')
img = cv2.imread('../data/messi5.jpg',0)
edges = cv2.Canny(img, 100, 200)

plt.subplot(121), plt.imshow(img, cmap='gray')
Expand Down
2 changes: 2 additions & 0 deletions ch20-图像金字塔/20.Apple_orange.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
GE = cv2.pyrUp(gpA[i])
L = cv2.subtract(gpA[i - 1], GE)#TODO error
lpA.append(L)
#cv2.error: /Users/play/Temp/opencv/modules/core/src/arithm.cpp:659: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function arithm_op


# generate Laplacian Pyramid for B
lpB = [gpB[5]]
Expand Down

0 comments on commit f5e6d58

Please sign in to comment.