0

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.

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.