Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. cv2.imshow("original", people)
  2. people1 = people.copy()
  3. gray = cv2.cvtColor(people, cv2.COLOR_BGR2GRAY)
  4. blur = cv2.GaussianBlur(gray, (1, 1), 1000)
  5. flag, thresh = cv2.threshold(blur, 120, 255, cv2.THRESH_BINARY)
  6. # Find contours
  7. contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
  8. contours = sorted(contours, key=cv2.contourArea, reverse=True)
  9. # Select long perimeters only
  10. perimeters = [cv2.arcLength(contours[i], True) for i in range(len(contours))]
  11. listindex = [i for i in range(15) if perimeters[i] > perimeters[0] / 2]
  12. numcards = len(listindex)
  13. # Show image
  14. imgcont = people.copy()
  15. [cv2.drawContours(imgcont, [contours[i]], 0, (255, 255, 255), 5) for i in listindex]
  16. # cv2.imshow("contur", imgcont)
  17.  
  18. mask = np.zeros(people.shape[: 2], np.uint8)
  19. mask1 = people - imgcont
  20. r, thresh1 = cv2.threshold(mask1, 128, 255, cv2.THRESH_BINARY)
  21. # cv2.imshow("mask", thresh1)
  22.  
  23. bgdModel = np.zeros((1, 65), np.float64)
  24. fgdModel = np.zeros((1, 65), np.float64)
  25. # mask[mask1 == 0] = 0
  26. # mask[mask1 == 255] = 1
  27. rect = (460, 10, 1200, 800)
  28. cv2.grabCut(people, mask, rect, bgdModel, fgdModel, 5, cv2.GC_INIT_WITH_RECT)
  29.  
  30. mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype("uint8")
  31.  
  32. people = people * mask2[:, :, np.newaxis]
  33.  
  34. cv2.imshow("catting", people)
  35.  
  36. fon = people1 - people
  37. cv2.imshow("catting1", fon)
  38. dst1 = cv2.cvtColor(people, cv2.COLOR_BGR2GRAY)
  39. r, g, b = cv2.split(people)
  40. dst = cv2.inpaint(fon, r, 3, cv2.INPAINT_TELEA)
  41. cv2.imshow("paint", dst)
  42. cv2.waitKey(0)
  43. cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement