r/opencv•
Weirdable

[Question] Trouble with cv.rectangle

Question

I'm pretty new to OpenCV and other python libraries in general, but I've been following a full tutorial guide to learn OpenCV alongside working on my own OpenCV project. The issue I'm running into is I'm using pyautogui to detect an object and store its X and Y value, which is all fine. But now comes the part of passing it into the cv.rectangle function.

The problem I'm having is when pyautogui stores the X and Y in a list, it does it like this:

[Box(left=965, top=355, width=226, height=221), Box(left=746, top=369, width=170, height=198)]

I want to know how I am able to use the left and top coordinates in a for loop, creating a rectangle. Here is the part of the code im having trouble with:

for y in newList #The list with the info above: if y != None: opp1 = int(y[0] * 1.5) opp2 = int(y[0] * 1.5) cv.rectangle(img, (y[0], y[0]), (opp1, opp2), (255,0,0), thickness=3)

I need y[0] to somehow be like y[0].left and y[0].top, but I can't figure it out. I'm still a noob so sorry if this question is easy or terribly worded

Posted Apr 21, 2021, 11:37 PM UTC

22
kdbhande•

Can you provide some image...what you want to achieve.

1
WeirdableOP•

I fixed it, sorry.

1