gpt4 book ai didi

python - 如何使用python遍历传递给函数参数的列表?

转载 作者:行者123 更新时间:2023-12-02 16:54:35 24 4
gpt4 key购买 nike

我正在尝试使用python在带有opencv和python的图像上的大量坐标处绘制框。我有2个列表,其中包含框的起点和终点的坐标。

startxy = [(0,0), (1,0), (2,0), ...etc.]  
endxy = [(1,1), (2,1), (3,1), ...etc.]

cv2.rectangle(img, startxy[0?], endxy[0?], color, thickness)

我知道我在递增坐标列表的索引时需要一遍又一遍地调用矩形函数,但是我是python的新手,正在努力增加和将这些值传递给矩形函数。

最佳答案

遍历两个列表的zip:

startxy = [(0,0),(1,0),(2,0),...etc.]
endxy = [(1,1),(2,1),(3,1),...etc.]

for start, end in zip(startxy, endxy):
cv2.rectangle(img, start, end, color, thickness)

关于python - 如何使用python遍历传递给函数参数的列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49929482/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com