在 OpenCV 中查找整个帧的质心坐标

Find Centroid Coordinate of whole frame in OpenCV

我正在互联网上搜索最佳代码以找到 OpenCV 框架的质心 XY 坐标,但没有找到。

我知道如何找到轮廓的 centroid/center,如下所示(在 python 中):

image = cv2.imread("test.png"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blurred = cv2.GaussianBlur(gray, (5, 5), 0)
thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]

# find contours in the thresholded image
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] 
#print cnts

# loop over the contours
for c in cnts:
    # compute the center of the contour
    M = cv2.moments(c)
    cX = int(M["m10"] / M["m00"])
    cY = int(M["m01"] / M["m00"])

Where CX, CY is the required XY-coordinates but how to find these coordinates for whole video-frame/image in OpenCV

请问有人能帮我吗?

这是对我的问题的直接而简单的回答,

image = cv2.imread('test.png')'
(h, w) = image.shape[:2] #w:image-width and h:image-height
cv2.circle(image, (w//2, h//2), 7, (255, 255, 255), -1) 

where, w//2, h//2 are the required frame/image centeroid's XY-coordinates.

我之前只是没有跳出框框,干杯:)