Guest User

Untitled

a guest
Nov 17th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. # Input image
  2. image = cv2.imread('oaHUs.jpg')
  3.  
  4. # Converts to grey for better reulsts
  5. gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  6.  
  7. # Converts to HSV
  8. hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
  9.  
  10. # HSV values
  11. lower_skin = np.array([5,36,53])
  12. upper_skin = np.array([19,120,125])
  13.  
  14. mask = cv2.inRange(hsv, lower_skin, upper_skin)
  15.  
  16. mask = cv2.erode(mask, None, iterations=2)
  17. mask = cv2.dilate(mask, None, iterations=2)
  18.  
  19. # Finds contours
  20. im2, cnts, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  21.  
  22. # Draws contours
  23. for c in cnts:
  24. if cv2.contourArea(c) < 3000:
  25. continue
  26.  
  27. (x, y, w, h) = cv2.boundingRect(c)
  28. cv2.rectangle(image, (x,y), (x+w,y+h), (0, 255, 0), 2)
  29.  
  30. ## BEGIN - draw rotated rectangle
  31. rect = cv2.minAreaRect(c)
  32. box = cv2.boxPoints(rect)
  33. box = np.int0(box)
  34. cv2.drawContours(image,[box],0,(0,191,255),2)
  35. ## END - draw rotated rectangle
  36.  
  37. cv2.imwrite('out.png', image)
Add Comment
Please, Sign In to add comment