Created
          October 17, 2019 15:13 
        
      - 
      
- 
        Save zhunhung/6a321d20a39fb6c6d5db63d93c8be980 to your computer and use it in GitHub Desktop. 
    Find contours in an image
  
        
  
    
      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
    
  
  
    
  | # convert image to grayscale | |
| imgray = cv2.cvtColor(img, cv.COLOR_BGR2GRAY) | |
| # apply threshold | |
| thresh = cv2.threshold(imgray, 127, 255, 0)[1] | |
| # find contours | |
| contours, hierarchy = cv.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) | |
| # draw contours on image | |
| cv2.drawContours(img, contours, -1, (0, 255, 0), 3) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment