我试图找到轮廓的质心,但在C++(OpenCV 2.3.1)中实现示例代码时遇到了问题.谁能帮我吗?
是否有一些好的和更好的方法来找到opencv中的轮廓质心,而不使用内置函数?
我的某些图像出现了零分割错误(即使其中许多图像都可以正常工作):
这是代码:
image = skimage.io.imread('test.png', False)
image_gray = skimage.io.imread('test.png', True)
blurred = cv2.GaussianBlur(img_as_ubyte(image_gray), (5, 5), 0)
thresh = threshold_li(blurred)
binary = blurred > thresh
binary_cv2 = img_as_ubyte(binary)
# find contours in the thresholded image
cnts = cv2.findContours(binary_cv2.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if imutils.is_cv2() else cnts[1]
# 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"])
# draw the contour and …Run Code Online (Sandbox Code Playgroud)