📜  Python 文件使用 OpenCV 写入所有边界框坐标 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:48.434000             🧑  作者: Mango

代码示例1
...
with open("coords.txt","w+") as file:
    for idx in range(len(contours)):
        x, y, w, h = cv2.boundingRect(contours[idx])
        mask[y:y+h, x:x+w] = 0
        file.write("Box {0}: ({1},{2}), ({3},{4}), ({5},{6}), ({7},{8})".format(idx,x,y,x+w,y,x+w,y+h,x,y+h))
        cv2.drawContours(mask, contours, idx, (255, 255, 255), -1)
        r = float(cv2.countNonZero(mask[y:y+h, x:x+w])) / (w * h)
...