Home > Mobile >  How can I use Python OpenCV to get the dimensions of each contoured object in the image?
How can I use Python OpenCV to get the dimensions of each contoured object in the image?

Time:07-22

I'm working on a project that involves automatically clicking on objects in a video game as they appear on the screen. Naturally, each object has a distinct blue outline - so I've isolated all colors from the image except for that blue color.

The image below shows an example of a pre-processed screenshot of the game. Using OpenCV in Python, how can I:

  • Get the position of the center-most pixel of each object?
  • Get the position of the top-most pixel of each object?

Image of three similar blobs

E.g.,

Image of three similar blobs with their centers and tops roughly pointed out

CodePudding user response:

You can use a relatively less-known cv2 method enter image description here

Output image:

enter image description here

The variable names explain the code pretty well already, after all, Python is similar to plain English!

  • Related