ACGPN icon indicating copy to clipboard operation
ACGPN copied to clipboard

Code for generate mask to clothe

Open josearangos opened this issue 4 years ago • 4 comments

@minar09 Thanks for share you ideas, I admire you a lot, Receive my regards

Hi, I want to share the code with i generated the mask for the clothes

import numpy as np
import cv2
from matplotlib import pyplot as plt


PATH_IMG ="5.jpg"
image = cv2.imread(PATH_IMG)
mask = np.zeros(image.shape[:2], dtype="uint8")
rect = (1, 1, mask.shape[1], mask.shape[0])
fgModel = np.zeros((1, 65), dtype="float")
bgModel = np.zeros((1, 65), dtype="float")
start = time.time()
(mask, bgModel, fgModel) = cv2.grabCut(image, mask, rect, bgModel,
                                       fgModel, iterCount=10, mode=cv2.GC_INIT_WITH_RECT)
outputMask = np.where((mask == cv2.GC_BGD) | (mask == cv2.GC_PR_BGD),0, 1)
outputMask = (outputMask * 255).astype("uint8")


plt.imshow(image)
plt.title('my picture')
plt.show()

image

plt.imshow(outputMask, cmap="gray")

image

josearangos avatar Nov 11 '20 21:11 josearangos

Hi @josearangos , thanks for your kind words and for sharing your code. Appreciate it. Thank you.

minar09 avatar Nov 12 '20 03:11 minar09

Hello @josearangos , Thanks for sharing the code, could you please also share, the correct format for saving the plot image into jpg, so that it can be directly used.

Thanks , Satyam.

p.s: RESOLVED cv2.imwrite('/filename.jpg', outputMask) will do the job

amrahsmaytas avatar Nov 16 '20 07:11 amrahsmaytas

Yes Mrs @amrahsmaytas cv2.imwrite(OUT_PATH,outputMask) is the correct code to save the image

josearangos avatar Nov 16 '20 14:11 josearangos

Yes Mrs @amrahsmaytas cv2.imwrite(OUT_PATH,outputMask) is the correct code to save the image

Thanks for the reply!

amrahsmaytas avatar Nov 16 '20 14:11 amrahsmaytas