Reputation: 355
I am able to detect the person and able to find the coordinates of the person and then i can crop the image. but i want to keep the person and remove all the background/ make it white background / copy the cropped image and paste it in another file in the same coordinates as obtained from the source.
This is my required image:
Upvotes: 2
Views: 736
Reputation: 1656
import cv2
import numpy as np
image = cv2.imread('img.png')
person = image[110:532, 250:516] # persons coordinates
h, w, c = image.shape
white_background = np.zeros([h, w, 3])
for y in range(h):
for x in range(w):
white_background[y,x] = [255,255,255] # fill with white pixels
white_background[110:532, 250:516] = person # paste the image into background image
cv2.imwrite('resized_centered.png', white_background)
Upvotes: 1