[英]OpenCV - minAreaRect // points is not a numerical tuple
錯誤點不是數字元組,而是 output。
# Converting image to a binary image
# ( black and white only image).
blur = cv2.GaussianBlur(img,(5,5),0)
_, threshold = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
contours, hierarchy = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
print(contours)
minArea = cv2.minAreaRect(contours)
輪廓是:
(array([[[747, 305]],
[[746, 306]],
[[745, 306]],
[[744, 307]],
[[743, 308]],
[[743, 309]],
[[744, 310]],
[[744, 311]],
[[744, 312]],
[[744, 313]],
[[757, 306]],
[[756, 306]],
[[755, 306]],
[[754, 306]],
[[753, 306]],
[[752, 305]],
[[751, 305]],
[[750, 305]],
[[749, 305]],
[[748, 305]]], dtype=int32),)
重載解析失敗:
- points 不是數字元組
- 參數“點”的預期 Ptr<cv::UMat>
有什么明顯的我做錯了嗎?
cv2.findContours
返回輪廓列表。 每個輪廓都是一個點列表。 因此它返回的contours
不是點列表,而是點列表的列表。
另一方面, cv2.minAreaRect
需要輸入單個點列表,因此當您用contours
喂它時會出錯。
您可以通過將contours
展平為單個點列表來解決它,如下所示:
contours_flat = np.vstack(contours).squeeze()
minArea = cv2.minAreaRect(contours_flat)
或者,您可以使用( idx
是基於 0 的輪廓索引)獲取contours
列表中每個輪廓的minAreaRect
:
minArea = cv2.minAreaRect(contours[idx])
你可以在這里看到更多關於輪廓的信息: Contours , cv::findContours
關於 minAreaRect: cv::minAreaRect
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.