generated from Data-Science-Community-SRM/template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
61 lines (53 loc) · 1.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from keep_alive import keep_alive
import discord
import os
from discord.ext import commands
from PIL import Image
from io import BytesIO
import asyncio
import cv2
import numpy as np
import matplotlib.pyplot as plt
from skimage.io import imread, imshow
from skimage.color import rgb2gray
from skimage import img_as_uint
from scipy.signal import convolve2d
client = commands.Bot(command_prefix='$')
kernel_edgedetection = np.array([[-1, -1, -1],
[-1, 8.5, -1],
[-1, -1, -1]])
def dodgeV2(image, mask):
return cv2.divide(image, 255-mask, scale=256)
@client.command()
async def filter1(ctx, user: discord.Member = None):
if user == None:
user = ctx.author
asset = user.avatar_url_as(size=128)
data = BytesIO(await asset.read())
pfp = Image.open(data)
#pfp=cv2.cvtColor(pfp, cv2.COLOR_BGR2GRAY)
pfp.save('profile.jpg')
image = cv2.imread('profile.jpg')
img_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
img_gray_inv = 255 - img_gray
img_blur = cv2.GaussianBlur(
img_gray_inv, ksize=(21, 21), sigmaX=0, sigmaY=0)
final = dodgeV2(img_gray, img_blur)
cv2.imwrite('profile1.jpg', final)
await ctx.send(file=discord.File('profile1.jpg'))
@client.command()
async def filter2(ctx, user: discord.Member = None):
if user == None:
user = ctx.author
asset = user.avatar_url_as(size=128)
data = BytesIO(await asset.read())
pfp = Image.open(data)
#pfp=cv2.cvtColor(pfp, cv2.COLOR_BGR2GRAY)
pfp.save('profile.jpg')
image = cv2.imread('profile.jpg')
morph_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
final = convolve2d(morph_gray, kernel_edgedetection)
cv2.imwrite('profile1.jpg', final)
await ctx.send(file=discord.File('profile1.jpg'))
keep_alive()
client.run(os.getenv('TOKEN'))