Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4.  
  5. def ex1():
  6.  
  7. img2 = cv2.imread('/home/sense/Downloads/znak1.jpg')
  8. # img2 = cv2.imread('znak2.png')
  9.  
  10. # Convert BGR to HSV
  11. hsv2 = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
  12. # hsv2 = cv2.cvtColor(img2, cv2.COLOR_BGR2HSV)
  13.  
  14.  
  15. # define range of blue color in HSV
  16. lower_yellow = np.array([10, 100, 100])
  17. upper_yellow = np.array([60, 255, 255])
  18.  
  19. mask = cv2.inRange(hsv2, lower_yellow, upper_yellow)
  20.  
  21. kernel = np.ones((3, 3), np.uint8)
  22. erosion = cv2.erode(mask, kernel, iterations=1)
  23. dilation = cv2.dilate(erosion, kernel, iterations=1)
  24.  
  25. image, contours, hierarchy = cv2.findContours(dilation, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  26. new = cv2.drawContours(img2, contours, -1, (0, 255, 0), 3)
  27. # Bitwise-AND mask and original image
  28. res = cv2.bitwise_and(img2, img2, mask=dilation)
  29.  
  30. cv2.imshow('frame', new)
  31. # cv2.imshow('mask', mask)
  32. cv2.imshow('res', res)
  33.  
  34. pass
  35.  
  36.  
  37. ex1()
  38. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement