How to get the coordinates of an element(or an image) in a Screenshot with python using OpenCv module?
To be more precise, I want to get the coordinates of a chosen object that could be for example (the image of a grey circle link here :https://www.clipartkey.com/view/xxwiJo_round-grey-button-png/ ) or any other element that I would define within a screenshot or another picture.
So how I want to proceed is taking a screenshot and using OpenCv or any other module to detect the element (grey circle) and get its center coordinates.
( If you know other modules to do my request there is no problem but it has to be in python language).
I Know that there are some pre-made functions to get the coordinates for eg :
getBoundingClientRect. I have made some research and found many posts but couldn't have my answer yet.
If someone could help me , I would be very grateful.
Thank you for your time! Have a great day!
Don't forget to up the post +1, to help more people see this post, even if you don't reply.
Vinish Kapoor
I have used the following code, and it seems to be working as you required.
Before running the below program, you need to install cv2 and matplotlib using the following commands:
pip3 install --no-binary opencv-python opencv-python
pip3 install matplotlib
I have downloaded that gray image into the current directory, and the image name is grayimg.png.
Following is the Python program to get coordinates of the image:
Output: