Guest User

Untitled

a guest
Oct 16th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. img = cv2.imread('imgs/bulls.jpg')
  2. hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
  3.  
  4. court_color = np.uint8([[[160,221,248]]])
  5. hsv_court_color = cv2.cvtColor(court_color, cv2.COLOR_BGR2HSV)
  6. hue = hsv_court_color[0][0][0]
  7.  
  8. # define range of blue color in HSV
  9. lower_color = np.array([hue - 10,10,10])
  10. upper_color = np.array([hue + 10,255,255])
  11.  
  12. # Threshold the HSV image to get only blue colors
  13. mask = cv2.inRange(hsv_img, lower_color, upper_color)
  14.  
  15. # Bitwise-AND mask and original image
  16. res = cv2.bitwise_and(img,img, mask= mask)
  17.  
  18. plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)), plt.title('Original Image'), plt.show()
  19. plt.imshow(mask, cmap='Greys'), plt.title('Mask'), plt.savefig('imgs/mask.jpg'), plt.show()
  20.  
  21. # Erosion
  22. kernel = np.ones((2,2),np.uint8)
  23. erosions2 = cv2.erode(mask,kernel,iterations = 5)
  24.  
  25. # Dilation
  26. dilation = cv2.dilate(mask,kernel,iterations = 3)
  27.  
  28. # Opening
  29. opening = cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)
  30.  
  31. # Closing
  32. closing = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, kernel)
Add Comment
Please, Sign In to add comment