如何提取每个正方形(边界框)中心的坐标?

发布于 2025-02-13 22:47:01 字数 897 浏览 2 评论 0原文

所以我需要每个橙色正方形的中心(边界框中的蓝色点)的坐标。 最好将它们列入元组列表。 这是我用来获取此图像的代码:

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()

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()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文