Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cv2.imshow("original", people)
- people1 = people.copy()
- gray = cv2.cvtColor(people, cv2.COLOR_BGR2GRAY)
- blur = cv2.GaussianBlur(gray, (1, 1), 1000)
- flag, thresh = cv2.threshold(blur, 120, 255, cv2.THRESH_BINARY)
- # Find contours
- contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
- contours = sorted(contours, key=cv2.contourArea, reverse=True)
- # Select long perimeters only
- perimeters = [cv2.arcLength(contours[i], True) for i in range(len(contours))]
- listindex = [i for i in range(15) if perimeters[i] > perimeters[0] / 2]
- numcards = len(listindex)
- # Show image
- imgcont = people.copy()
- [cv2.drawContours(imgcont, [contours[i]], 0, (255, 255, 255), 5) for i in listindex]
- # cv2.imshow("contur", imgcont)
- mask = np.zeros(people.shape[: 2], np.uint8)
- mask1 = people - imgcont
- r, thresh1 = cv2.threshold(mask1, 128, 255, cv2.THRESH_BINARY)
- # cv2.imshow("mask", thresh1)
- bgdModel = np.zeros((1, 65), np.float64)
- fgdModel = np.zeros((1, 65), np.float64)
- # mask[mask1 == 0] = 0
- # mask[mask1 == 255] = 1
- rect = (460, 10, 1200, 800)
- cv2.grabCut(people, mask, rect, bgdModel, fgdModel, 5, cv2.GC_INIT_WITH_RECT)
- mask2 = np.where((mask == 2) | (mask == 0), 0, 1).astype("uint8")
- people = people * mask2[:, :, np.newaxis]
- cv2.imshow("catting", people)
- fon = people1 - people
- cv2.imshow("catting1", fon)
- dst1 = cv2.cvtColor(people, cv2.COLOR_BGR2GRAY)
- r, g, b = cv2.split(people)
- dst = cv2.inpaint(fon, r, 3, cv2.INPAINT_TELEA)
- cv2.imshow("paint", dst)
- cv2.waitKey(0)
- cv2.destroyAllWindows()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement