我有一个像这样的数组:[[x1,y1,x2,y2),(x1,y1,x2,y2),(x1,y1,x2,y2),(x1,y1,x2,y2)],和我的代码是:
def draw_lines(image, lines, color=[255, 0, 0], thickness=2, make_copy=True):
if make_copy:
image = np.copy(image)
cleaned = []
for line in lines:
for x1,y1,x2,y2 in line:
if abs(x2-x1) <=10 and abs(y2-y1) >=19 and abs(y2-y1) <= 70 :
cleaned.append((x1,y1,x2,y2))
cv2.line(image, (x1, y1), (x2, y2), color, thickness)
print(" No lines detected: ", len(cleaned))
print (cleaned)
return image
在if语句中,我想添加一个新的“ and”条件,该条件将数组当前x1值与数组下一个x1值进行比较。例如:x1 [i + 1] -x1 [i]> 10
在这种情况下,如何使用索引和迭代?
在此先感谢您的帮助!
我不是这方面的佼佼者,但我认为这是一个网站,您应该查看该网站,希望对您有所帮助:
https://www.fluentcpp.com/2018/10/26/how-to-access-the-index-of-the-current-element-in-a-modern-for-loop/
您可以这样做:
或者如果您想将各个坐标作为单独的变量访问:
请注意,循环将停止在列表中的最后一个位置。