ACGPN
ACGPN copied to clipboard
Code for generate mask to clothe
@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()
plt.imshow(outputMask, cmap="gray")
Hi @josearangos , thanks for your kind words and for sharing your code. Appreciate it. Thank you.
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
Yes Mrs @amrahsmaytas cv2.imwrite(OUT_PATH,outputMask) is the correct code to save the image
Yes Mrs @amrahsmaytas cv2.imwrite(OUT_PATH,outputMask) is the correct code to save the image
Thanks for the reply!