This commit is contained in:
Yasir Aris M 2024-07-29 11:38:39 +07:00 committed by GitHub
parent 7efa2f83ba
commit a44c9cc3dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 6 deletions

View file

@ -174,12 +174,9 @@ def isValidURL(str):
@asyncify @asyncify
async def gen_trans_image(msg, path): def gen_trans_image(source, path):
# Download image
dl = await msg.download()
# load image # load image
img = cv2.imread(dl) img = cv2.imread(spurce)
# convert to graky # convert to graky
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
@ -210,5 +207,4 @@ async def gen_trans_image(msg, path):
# save resulting masked image # save resulting masked image
cv2.imwrite(path, result) cv2.imwrite(path, result)
os.remove(dl)
return path return path

View file

@ -179,8 +179,10 @@ async def removebg(_, ctx: Client):
return await ctx.reply_msg("Please reply image.") return await ctx.reply_msg("Please reply image.")
if not ctx.reply_to_message.photo: if not ctx.reply_to_message.photo:
return await ctx.reply_msg("Only support photo for remove background.") return await ctx.reply_msg("Only support photo for remove background.")
source = await ctx.reply_to_message.download()
await gen_trans_image(ctx.reply_to_message, f"transp_bckgrnd-{ctx.from_user.id}.png") await gen_trans_image(ctx.reply_to_message, f"transp_bckgrnd-{ctx.from_user.id}.png")
await ctx.reply_photo(f"transp_bckgrnd-{ctx.from_user.id}.png") await ctx.reply_photo(f"transp_bckgrnd-{ctx.from_user.id}.png")
os.remove(source)
os.remove(f"transp_bckgrnd-{ctx.from_user.id}.png") os.remove(f"transp_bckgrnd-{ctx.from_user.id}.png")