【问题标题】:Find Centroid Coordinate of whole frame in OpenCV在 OpenCV 中查找整个框架的质心坐标
【发布时间】:2018-10-28 08:09:58
【问题描述】:

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

我知道如何找到轮廓的质心/中心,如下(在 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"])

其中CXCY 是所需的 XY 坐标 但是如何在 OpenCV 中找到整个视频帧/图像的这些坐标

请任何人都可以帮助我吗?

【问题讨论】:

    标签: opencv frame centroid


    【解决方案1】:

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

    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) 
    

    其中,w//2, h//2 是所需的帧/图像中心点的 XY 坐标。

    我之前只是没有开箱即用,干杯:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 1970-01-01
      • 1970-01-01
      • 2013-08-07
      • 2016-05-29
      • 2015-03-27
      • 1970-01-01
      相关资源
      最近更新 更多