opencv 학습-윤곽 그리기

2164 단어
import cv2
import numpy as np
import matplotlib.pylab as plt
import scipy.misc as misc

'''
   cv2.findContours()      ,        ,    
      ,          。      ,      ,   
   ,    (   )    。  (      )    Python
  ,             。          Numpy   , 
      (x,y)   。
   cv2.drawContours()          。        
          。            ,        , 
  Python   。           (           ,  
   -1        )。                
'''
img = cv2.imread('images/33.jpg',0)
#ret,th = cv2.threshold(img,127,255,0)
ret,th = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
#image = th
image, contours, hierarchy = cv2.findContours(th,
                                cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
# draw all the contours
img = cv2.drawContours(img, contours, -1, (0,255,0), 3)
# draw an individual contour
cnt = contours[4]
img1 = cv2.drawContours(img, [cnt], 0, (0,255,0),3)

cv2.imshow('result1.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.waitKey(1)
cv2.waitKey(1)
cv2.waitKey(1)
cv2.waitKey(1)

좋은 웹페이지 즐겨찾기