【发布时间】:2021-04-16 19:28:27
【问题描述】:
所以我刚开始学习 openCV,我正在学习加入和屏蔽图像。因此,在实际做一些事情时,我遇到了以下代码的两个问题。
...
# HSV values
lower_bounds = numpy.array([h_min, s_min, v_min])
upper_bounds = numpy.array([h_max, s_max, v_max])
# Generating a mask
mask = cv2.inRange(img_hsv, lower_bounds, upper_bounds)
# Using this to convert the image into a 3 channel image so as to
# join it with other images below using the hstack and stack
# **Line 1**
th_mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR)
# Using bitwise_and with img as src1 and three channel mask as src2
# **Line 2**
result = cv2.bitwise_and(img, th_mask)
horizontal_stack_1 = numpy.hstack((img, img_hsv))
horizontal_stack_2 = numpy.hstack((th_mask, result))
vertical_stack = numpy.vstack((horizontal_stack_1, horizontal_stack_2))
...
所以我的问题是:
- 代码中的第 1 行 是否可以正确生成三通道图像以将其与其他三通道图像连接起来?如果不是更好的解决方案是什么?
-
Line 2 和
result = cv2.bitwise_and(img, img, mask = mask)有什么区别,如果我只需要提取特定的颜色,哪种方法更好?
谢谢。
【问题讨论】:
标签: python python-3.x opencv computer-vision mask