#๐Ÿ”’ Get generic bbox of numpy array instead of magic number bbox

10 messages ยท Page 1 of 1 (latest)

thin quiver
#

I'm trying to get a section of a set of screenshots and I always know what exact coordinates that section will be. I don't want to use magic numbers for the coordinates, but outside of an ugly [XMIN:XMAX, YMIN:YMAX] I'm not sure how I would be able to grab such a section from the array.

This is the code I'm working with:

screen_img = cv2.imread( screen_fullpath )
talisman_img = screen_img[48:498, 852:1262]
subtle sphinxBOT
#

@thin quiver

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

magic crown
#

Not sure I get the question. I don't think screen_img[48:498, 852:1262] is ugly?

#

i guess you could instead write your own BBox dataclass with a method to take such a part from an array.

thin quiver
#

I don't think it is either, but I'd like to set it as a constant instead of just magic numbering it in the middle of my code

magic crown
#

well, you could go the "your own bbox dataclass" way, and do

TALISMAN_BBOX = BBox(top=48, left=852, bottom=498, right=1262)
# ...
TALISMAN_BBOX.crop_arr(screen_img)
spare prism
#

Or create two slice objects and store them as constants; although I don't think that that would be better personally.

thin quiver
#

yeah that also seems a bit awkward

subtle sphinxBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.