Contours.py 468 字节
Newer Older
youcans_'s avatar
youcans_ 已提交
1 2 3 4 5 6 7
import cv2 as cv

if __name__ == '__main__':
    img = cv.imread("Contours.jpg", flags=1)
    imgGray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

    ret, thresh = cv.threshold(imgGray, 127, 255, cv.THRESH_BINARY_INV)
F
feilong 已提交
8 9
    contours, hierarchy = cv.findContours(
        thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
youcans_'s avatar
youcans_ 已提交
10 11 12
    contourPic = cv.drawContours(img, contours, -1, (0, 0, 255), 2)

    cv.imshow("ContourPicture", contourPic)
F
feilong 已提交
13 14
    cv.waitKey(0)
    cv.destroyAllWindows()