【发布时间】:2021-04-24 15:41:14
【问题描述】:
我想找到通过 blob 质心的 blob 的主轴。我能够找到 blob 的质心,但是如何找到主轴?
这是我尝试过的:
import cv2
import numpy as np
img = cv2.imread('skin6.jpg')
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh2 = cv2.threshold(imgray, 155, 255, cv2.THRESH_BINARY_INV)
#find the maximum contour
contours, heir = cv2.findContours(thresh2, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
c = max(contours, key = cv2.contourArea)
tmpArea = np.zeros(img.shape)
cv2.drawContours(tmpArea,[c],0,(255, 255, 255),cv2.FILLED)
#centroid
M = cv2.moments(c)
cx = int(M['m10']/M['m00'])
cy = int(M['m01']/M['m00'])
cv2.circle(tmpArea, (cx, cy), 5, (0, 0, 255), -1)
cv2.imshow("tmpArea", tmpArea)
cv2.waitKey(0)
这些是我使用的图像:
我期待这样的事情。它应该与轮廓正确连接: Expected
【问题讨论】:
标签: python opencv blob axis centroid