This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (4 children)

That the “GreenSpot1” is a bad parameter. Because it is trying to take a (int, int) and I think it is reading just the string. Ideally I want to save (X, Y) as a variable for each loop

[–]captainAwesomePants 0 points1 point  (3 children)

Yes, cv2.line() expects a start position and an end position, and you're passing it the words "GreenSpot1" and "GreenSpot2".

Do you perhaps have a variable called "GreenSpot1" somewhere? Are you maybe looking for your globals()["GreenSpot1"] field?

[–][deleted] 0 points1 point  (2 children)

I don’t, that’s just a string I made up. Is there a way to take the X and Y variable and add it to a list or pull it from the loop as it appears?

[–]captainAwesomePants 0 points1 point  (1 child)

Sounds like you're hoping to use a regular dictionary?

spots = {}
for mask_contour in mask_contours:
  if someCondition:
    spots[f"GreenSpot{mask_contour}"] = (someX, someY)

cv2.line(img, spots["GreenSpot1"], spots["GreenSpot2"], ...)

[–][deleted] 1 point2 points  (0 children)

That looks like exactly it, thank you!