0

enter image description here

So I need coordinates of centers (blue dots in the bounding box) of each orange squares. It would be good to put them into the list of tuples. Here is the code I used to get this image:

import cv2 as cv
import numpy as np 
from cvzone.ColorModule import ColorFinder
import cvzone 

img = cv.imread("image_path")

myColorFinder = ColorFinder(False)
hsvValsOrange = {'hmin': 0, 'smin': 164, 'vmin': 0, 'hmax': 179, 'smax': 255, 'vmax': 255}

imgColor,mask = myColorFinder.update(img,hsvValsOrange)
  
imgContour, contours = cvzone.findContours(img,mask, minArea=1000)

  
if len(contours):
    data = contours[0]["center"][0],h-contours[0]["center"][1],int(contours[0]["area"])
    print(data)

imgStack = cvzone.stackImages([img,imgColor,mask,imgContour],2,0.5)
   
cv.imshow("Image", imgStack)

cv.waitKey(0)
cv.destroyAllWindows()
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
noca951
  • 41
  • 2
  • 1
    So is there some issue with your code? Does it give an error? Get the contours. Then get the centroids from the contours. Centroids are computed from image moments. – fmw42 Jul 08 '22 at 15:03
  • 1
    Find the [centroid of each contour](https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html) – Jeru Luke Jul 08 '22 at 15:04
  • 1
    @JeruLuke please stop erasing the cvzone tags from all those questions. cvzone is a separate library with its own issues, and this tag is important. I will review all the edits and reapply cvzone tags where appropriate (error directly caused by cvzone code, or issue is related). if you need to debate this, I've created an "OpenCV" chat room on stack overflow. – Christoph Rackwitz Jul 08 '22 at 16:17
  • 1
    @ChristophRackwitz I'm really sorry. I just found out about it. It can be installed by `pip` as well. The tag didn't have any details regarding the library. It won't happen again. – Jeru Luke Jul 08 '22 at 20:25
  • 1
    I once tried to give the tag a description but that must have been dropped from the edit queue for some reason. this site is broken. – Christoph Rackwitz Jul 08 '22 at 20:34
  • @ChristophRackwitz Can you please share link for the "OpenCV" chat room? – Jeru Luke Jul 11 '22 at 11:55
  • 1
    https://chat.stackoverflow.com/rooms/246282/opencv but I'm not watching that – Christoph Rackwitz Jul 11 '22 at 11:59

0 Answers0