我有一个循环修改water_depth类型为 2D numpy 数组的元素float。该阵列包含每个像素的水深,范围通常在 0 到 1.5m 之间。我想用这个不断变化的数组制作一个视频:每次迭代都可以是视频中的一个帧。我只发现这个链接解释了一个类似的问题,并建议使用 cv2 VideoWriter。问题是我的 numpy 数组是一个浮点数,而不是整数。这是否意味着我需要在每次迭代中对我的数组进行某种预处理?
import numpy as np
water_depth = np.zeros((500,700), dtype=float)
for i in range(1000):
random_locations = np.random.random_integers(200,450, size=(200, 2))
for item in random_locations:
water_depth[item[0], item[1]] += 0.1
#add this array to the video
Run Code Online (Sandbox Code Playgroud) 为了提取颜色,我们有这个功能
# define range of blue color in HSV
lower_blue = np.array([110,50,50])
upper_blue = np.array([130,255,255])
# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_blue, upper_blue)
Run Code Online (Sandbox Code Playgroud)
我们如何实际可视化我在hsv空间定义的范围(lower_blue,upper_blue)?另外我如何实际绘制hsv颜色,但它不起作用......?我有这个代码:
upper = np.array([60, 255, 255])
upper = cv2.cvtColor(upper, cv2.COLOR_HSV2BGR)
upper = totuple(upper/-255)
print(upper)
plt.imshow([[upper]])
Run Code Online (Sandbox Code Playgroud)