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.
We have moved to a new forum at http://jevois.usc.edu, please check it out. The forum at jevois.org/qa will not allow new user registrations but is maintained alive for its useful past questions and answers.

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":


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