简体   繁体   中英

How to iterate through a list passed to a function parameter with python?

I am trying to use python to draw boxes at a large number of coordinates on an image with opencv and python. I have 2 lists that contain the coordinates of the start and end points of the boxes.

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)

I know I need to call the rectangle function over and over while I increment the index of my coordinate list, but I'm new to python and struggling with how to increment and pass these values to the rectangle function.

Iterate over the the zip of the two lists:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM