如何提取每个正方形(边界框)中心的坐标?
所以我需要每个橙色正方形的中心(边界框中的蓝色点)的坐标。 最好将它们列入元组列表。 这是我用来获取此图像的代码:
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()
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论