-1

I have a 1920x1080 monitor and some X,Y coordinates (black dots) based on the Cartesian coordinate system (center of the screen=0,0). What I want to achieve is to check whether any of these X,Y coordinates fall within a prespecified rectangle region of interest (ROI). I have access to all the X,Y coordinates (all the dots in the image below) and the coordinates of the rectangle ROI (only its center coordinates, but I can calculate top left, bottom right if needed). My question is how I can check if any of the dots are inside the ROI using python?

Thanks in advance. enter image description here

Phoenix
  • 73
  • 6
  • 7
    Does this answer your question? [How to detect if a point is contained within a bounding rect - opecv & python](https://stackoverflow.com/questions/33065834/how-to-detect-if-a-point-is-contained-within-a-bounding-rect-opecv-python) – Bedir Yilmaz Aug 18 '21 at 10:20
  • @BedirYilmaz Not really. Assuming that the top-left coordinate of the ROI is `(-760,-200)`, `(W)idth=150` & `(H)eigth=150`. And the coordinates of one of the dots inside is `X=-740,Y=-220`.Based on the correct answer from the the thread you posted, we have -760<-740<-610 and -200<-220<-70. Given that only one of these comparisons is true we can say that the dot is not within the rectangle. However, the dot falls within the ROI, as shown in the image. – Phoenix Aug 18 '21 at 11:34
  • I think you calculate it in wrong way - you should `substract` values `H`, not `add` it - and you will have `-200>-220>-350` – furas Aug 18 '21 at 12:29
  • since your coordinate system grows to the right and to the top, you should use the **bottom left** corner, not the top left corner. if you have to use the top left corner, you have to subtract height (and add width). the math is trivial, if you don't confuse yourself. – Christoph Rackwitz Aug 18 '21 at 13:30

1 Answers1

2

This schema is representing your centerbased ROI(x=-760,y=-200) : enter image description here

Are on the ROI any point X,Y with :

  • X between -685 and -835 (-835<X<-685)
  • AND Y between -125 and -275 (-275<Y<-125)

You should be able then to program it using Python.

Nicos44k
  • 88
  • 7
  • The logic is correct but the solution is specific to this quadrant of the screen. If my ROI is in another quadrant then this solution becomes messy. Thanks for your time, though. – Phoenix Aug 18 '21 at 12:20
  • 2
    since numbers have signs, this should not be "messy" at all – Christoph Rackwitz Aug 18 '21 at 13:29