我正在尝试细分足球场。我找到了代表野外区域的最大轮廓。我需要使用该区域生成一个二进制图像。
我正在关注一份研究论文,并遵循了所有步骤,包括
我已经使用Contours完成了此操作,并且具有代表场区域的最大轮廓。
我需要使用此特定轮廓来生成新的二进制图像,该图像仅包含该轮廓的区域。
# Find Largest Blob
# mask is the processed binary image
# using that mask I find the contours and draw them on original
#image
contours, hierarchy = cv2.findContours(mask, cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_NONE)
largest_blob = max(contours, key=cv2.contourArea)
cv2.drawContours(image, largest_blob, -1, (0, 0, 255), 2)
答案 0 :(得分:0)
您可以这样做,首先找到这些轮廓的边界矩形,
边框由绿色框指示
x,y,w,h = cv2.boundingRect(cnt)
然后使用它们裁剪图像
field = img[y:y+h, x:x+w, :]
然后您可以将二值化应用于field
对象,更多信息可以在这里找到
https://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html
答案 1 :(得分:0)