Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added deep-fry/42.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deep-fry/e0eff0403df8f7245c0f2e3d792390d0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deep-fry/fry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deep-fry/iczero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deep-fry/image0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deep-fry/output-temp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions deep-fry/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys

import numpy as np
import cv2

# reads in the image
image = cv2.imread(sys.argv[1], flags=cv2.IMREAD_COLOR)

def fry(image, saturation):
# sets the green channel equal to the
# increase saturation
hsvImg = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
hsvImg[...,1] = hsvImg[...,1]*saturation
image=cv2.cvtColor(hsvImg,cv2.COLOR_HSV2BGR)

image[...,0] = image[...,0] * 1.1 # sets the red channel to the green channel
image[...,1] = image[...,0] * 1.1 # sets the red channel to the green channel
return image

def sharp(image):
# sharpening kernel
kernel = np.array([[0, -1, 0],
[-1, 5,-1],
[0, -1, 0]])
return cv2.filter2D(src=image, ddepth=-1, kernel=kernel)

cv2.imwrite("fry.png", fry(image, 1.4))
cv2.imwrite("output.png", fry(sharp(sharp(image)), 5))
29 changes: 27 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import os
import os.path

import numpy as np
import cv2

try:
TOKEN = os.environ["BONOBOT_TOKEN"]
except:
Expand Down Expand Up @@ -159,6 +162,21 @@ def get_best_random(users, members):
currRandom.add(candidate)
users[i] = candidate

def fry(image):
# sets the green channel equal to the
# increase saturation
hsvImg = cv2.cvtColor(image,cv2.COLOR_BGR2HSV)
hsvImg[...,1] = hsvImg[...,1]*5
image=cv2.cvtColor(hsvImg,cv2.COLOR_HSV2BGR)

return image

def sharp(image):
# sharpening kernel
kernel = np.array([[0, -1, 0],
[-1, 5,-1],
[0, -1, 0]])
return cv2.filter2D(src=image, ddepth=-1, kernel=kernel)

class BonoboCog(commands.Cog):
def __init__(self, bot):
Expand All @@ -170,8 +188,12 @@ async def get_avatar(self, user: Union[nextcord.User, nextcord.Member]) -> Image
avatar_bytes = await user.display_avatar.read()
return Image.open(BytesIO(avatar_bytes))

@commands.command(aliases=["nft"])
async def deepfry(self, ctx, users:commands.Greedy[DiscordMonke]):
await self.bonobo(ctx,users,True)

@commands.command(aliases=["bonobot"])
async def bonobo(self, ctx, users: commands.Greedy[DiscordMonke]):
async def bonobo(self, ctx, users: commands.Greedy[DiscordMonke], deepfry=False):
if len(users) == 0 and len(ctx.message.clean_content.split()) == 1:
users = [LazyRandom()] * random.choice(tuple(self.templates)).faces
get_best_random(
Expand Down Expand Up @@ -200,7 +222,10 @@ async def bonobo(self, ctx, users: commands.Greedy[DiscordMonke]):
im = pasteImg(
im, top, template.upperleftcord(count), template.lowerrightcord(count)
)

if deepfry:
opencvImage = cv2.cvtColor(np.array(im), cv2.COLOR_RGB2BGR)
im = Image.fromarray(fry(sharp(sharp(opencvImage))))
# deepfry
buffer = BytesIO()
im.save(buffer, "png")
buffer.seek(0)
Expand Down
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ imageio == 2.9.0

# Bonobot/main.py: 3,4
nextcord == 2.0.0a3

# numpy
numpy

# opencv
opencv-python