()
| 30 | |
| 31 | |
| 32 | def close_demo(): |
| 33 | src = cv.imread("morph3.png") |
| 34 | cv.namedWindow("input", cv.WINDOW_AUTOSIZE) |
| 35 | cv.imshow("input", src) |
| 36 | |
| 37 | # 图像二值化 |
| 38 | gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY) |
| 39 | ret, binary = cv.threshold(gray, 0, 255, cv.THRESH_BINARY | cv.THRESH_OTSU) |
| 40 | |
| 41 | # 闭操作 |
| 42 | se = cv.getStructuringElement(cv.MORPH_ELLIPSE, (15, 15), (-1, -1)) |
| 43 | binary = cv.morphologyEx(binary, cv.MORPH_CLOSE, se) |
| 44 | cv.imwrite("close.png", binary) |
| 45 | cv.imshow("close", binary) |
| 46 | |
| 47 | #open_demo() |
| 48 | close_demo() |