Created
December 24, 2018 22:14
-
-
Save pravj/2be7a1c308b969735c1387839503a600 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# grayscale version of the single color image | |
image_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) | |
# bilateral filter is effective when you want to | |
# keep the edges sharp while removing noise | |
image_gray = cv2.bilateralFilter(image_gray, 10, 50, 50) | |
# find contour in gray scale image after applying erosion and dilation | |
_, thresh = cv2.threshold(image_gray, 75, 255, 0) | |
thresh = cv2.erode(thresh, None, iterations=2) | |
thresh = cv2.dilate(thresh, None, iterations=2) | |
_, contours, _ = cv2.findContours( | |
thresh, | |
cv2.RETR_EXTERNAL, | |
cv2.CHAIN_APPROX_SIMPLE | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment