-
-
Save zinnunkebi/ba3ddd917321fac4b79b07db4ce8d4e5 to your computer and use it in GitHub Desktop.
watershed_algorithim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from matplotlib import pyplot as plt | |
def pause(): | |
# pause | |
keycode = cv2.waitKey(0) | |
# ESC key to close imshow | |
if keycode == 27: | |
cv2.destroyAllWindows() | |
img_bgr = cv2.imread('./image/S__26132483.png') | |
cv2.imshow("img_bgr", img_bgr) | |
pause() | |
img_bitwise_not_bgr = cv2.bitwise_not(img_bgr) | |
cv2.imshow("img_bitwise_not_bgr", img_bitwise_not_bgr) | |
pause() | |
img_bitwise_not_bgr2gray = cv2.cvtColor(img_bitwise_not_bgr, cv2.COLOR_BGR2GRAY) | |
cv2.imshow("img_bitwise_not_bgr2gray", img_bitwise_not_bgr2gray) | |
pause() | |
ret, img_binary = cv2.threshold(img_bitwise_not_bgr2gray, 150,255,cv2.THRESH_BINARY) | |
cv2.imshow("img_binary", img_binary) | |
pause() | |
contours, hierarchy = cv2.findContours(img_binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) | |
img_contour = cv2.drawContours(img_bgr, contours, -1, (0, 255, 0), 2) | |
cv2.imshow("img_contour", img_contour) | |
pause() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment