Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for generate mask to clothe #6

Open
josearangos opened this issue Nov 11, 2020 · 4 comments
Open

Code for generate mask to clothe #6

josearangos opened this issue Nov 11, 2020 · 4 comments

Comments

@josearangos
Copy link

@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

@minar09
Copy link
Owner

minar09 commented Nov 12, 2020

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

@amrahsmaytas
Copy link

amrahsmaytas commented Nov 16, 2020

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

@josearangos
Copy link
Author

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

@amrahsmaytas
Copy link

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

Thanks for the reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants