Welcome new user! You can search existing questions and answers without registering, but please register to post new questions and receive answers. Note that due to large amounts of spam attempts, your first three posts will be manually moderated, so please be patient.
Because of un-manageable amounts of spam despite our use of CAPTCHAs, email authorization, and other tools, we have discontinued this forum (see the 700k+ registered users with validated email addresses at right?). Please email us any questions or post bug reports and feature requests on GitHub at https://github.com/jevois -- The content below remains available for future reference.

Tuple has no attribute

0 votes
I'm running python code on the Jevois to identify rectangular areas and pass them over USB to a raspberry pi. All the open CV code seems to work fine and I obtain my RotatedRect using minAreaRect. I encounter a problem when I try to access attributes of the rectangle. For example, if I try to access rect.center.x, I'm told that the 'tuple' has no attribute 'center'. If I try to dump the RotatedRect structure using json.dump, all of the data is there, but there are no tuple names.

I'm a python newbie, so hopefully this is something dumb I'm doing and easy to fix.

Any and all assistance is appreciated.
asked Feb 15, 2019 in Programmer Questions by kinahawi (220 points)

1 Answer

+1 vote
 
Best answer

How about this hit from googling "python minAreaRect":

https://www.programcreek.com/python/example/89463/cv2.minAreaRect

example 4 tells you:

  # help(cv2.minAreaRect)
  (x, y), (width, height), rect_angle = rectangle
so you could try that code. Or, if you just want to extract the fields from your rectangle, I guess rect[0] is (x, y) and rect[0][0] is x
and rect[1] is (width, height) and rect[1][0] is width
and so on, the other examples should help you.
answered Feb 20, 2019 by JeVois (46,580 points)
selected Feb 20, 2019 by kinahawi
...