我有一个包含 580 帧的视频。我需要能够从视频中检测到绿色并创建一个掩码,以便在找到绿色的位置放置零值,其余的应该是 255。我已经将视频转换为 HSV 格式并使用嵌套的 for 循环和它大约需要一个小时才能做到这一点我想知道是否有更快的方法来做到这一点。
这是我当前的代码
for i in range(0, len(temp)):
temp[i] = cv2.cvtColor(temp[i], cv2.COLOR_BGR2HSV)
for k in range(0, len(temp)):
for i in range(0, len(temp[k])):
for j in range(0, len(temp[k][i])):
if(temp[k][i][j][0] > 50 and temp[k][i][j][0] < 65 and temp[k][i][j][2] > 150):
temp1[k][i][j][0] = 0
temp1[k][i][j][1] = 0
temp1[k][i][j][2] = 0
else:
temp1[k][i][j][0] = 255
temp1[k][i][j][1] = 255
temp1[k][i][j][2] = 255
temp 是我的 HSV 数组, temp1 是我正在创建的掩码