OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

how to find coordinates of selected objects openCV

  • Thread starter Thread starter user582426
  • Start date Start date
U

user582426

Guest
In general, I highlighted these objects in red using openCV, but I don’t know how to find their coordinates:

picture 1


Initially it all looked like this:

picture 2


Code:
import cv2
import matplotlib.pyplot as plt

img = cv2.imread('test.png')
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


_, binary = cv2.threshold(gray_img, 125, 255, cv2.THRESH_BINARY)

contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, 
cv2.CHAIN_APPROX_SIMPLE)


img = cv2.drawContours(img, contours, -1, (255, 0, 0), 2)

plt.imshow(img)
plt.show()
<p>In general, I highlighted these objects in red using openCV, but I don’t know how to find their coordinates:</p>
<p><img src="https://i.sstatic.net/Qs11p8cn.png" alt="picture 1" /></p>
<p>Initially it all looked like this:</p>
<p><img src="https://i.sstatic.net/M9mwLXpB.png" alt="picture 2" /></p>
<pre><code>import cv2
import matplotlib.pyplot as plt

img = cv2.imread('test.png')
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)


_, binary = cv2.threshold(gray_img, 125, 255, cv2.THRESH_BINARY)

contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)


img = cv2.drawContours(img, contours, -1, (255, 0, 0), 2)

plt.imshow(img)
plt.show()
</code></pre>
 

Latest posts

Top