diff options
author | carp <25677564+carp@users.noreply.github.com> | 2020-07-13 13:29:50 -0400 |
---|---|---|
committer | carp <25677564+carp@users.noreply.github.com> | 2020-07-13 13:29:50 -0400 |
commit | 3e7c2e260384a3e381f01717fd71a694b71cae6e (patch) | |
tree | 2e6a14546026baea5ef1b6267a30a3a2acd3d1e2 /utils.py | |
parent | d843c598deb492a53303cb18a0746584b6723dbf (diff) | |
download | yaoi-communism-3e7c2e260384a3e381f01717fd71a694b71cae6e.tar.gz yaoi-communism-3e7c2e260384a3e381f01717fd71a694b71cae6e.zip |
code format
Diffstat (limited to 'utils.py')
-rw-r--r-- | utils.py | 45 |
1 files changed, 30 insertions, 15 deletions
@@ -4,31 +4,46 @@ from shapely.geometry import Polygon import cv2
import os.path
import random
-import subprocess
+import subprocess
import json
from colorthief import ColorThief
+
def draw_with_border(x, y, message, color_fill, color_border, font, draw):
border_width = max((font.size // 25), 2)
-
- for i in range(1,border_width+1):
- draw.text((x,y+i), message, fill=color_border, font=font)
- draw.text((x,y-i), message, fill=color_border, font=font)
- draw.text((x+i,y), message, fill=color_border, font=font)
- draw.text((x-i,y), message, fill=color_border, font=font)
+ for i in range(1, border_width + 1):
+ draw.text((x, y + i), message, fill=color_border, font=font)
+ draw.text((x, y - i), message, fill=color_border, font=font)
+ draw.text((x + i, y), message, fill=color_border, font=font)
+ draw.text((x - i, y), message, fill=color_border, font=font)
- draw.text((x-i,y-i), message, fill=color_border, font=font)
- draw.text((x-i,y+i), message, fill=color_border, font=font)
- draw.text((x+i,y-i), message, fill=color_border, font=font)
- draw.text((x+i,y+i), message, fill=color_border, font=font)
+ draw.text((x - i, y - i), message, fill=color_border, font=font)
+ draw.text((x - i, y + i), message, fill=color_border, font=font)
+ draw.text((x + i, y - i), message, fill=color_border, font=font)
+ draw.text((x + i, y + i), message, fill=color_border, font=font)
draw.text((x, y), message, fill=color_fill, font=font)
def detect(filename):
- result = subprocess.run(['conda',"activate","detection","&&","python", 'anime-face-detector/main.py ',"-i",filename,"-o","output.json"],shell=True,stdout=subprocess.DEVNULL)
- with open("output.json","r") as f:
+ result = subprocess.run(
+ [
+ "conda",
+ "activate",
+ "detection",
+ "&&",
+ "python",
+ "anime-face-detector/main.py ",
+ "-i",
+ filename,
+ "-o",
+ "output.json",
+ ],
+ shell=True,
+ stdout=subprocess.DEVNULL,
+ )
+ with open("output.json", "r") as f:
output = json.load(f)
print(output)
return [f["bbox"] for f in output[filename]]
@@ -96,7 +111,7 @@ def randomize_location(image, messages, font): placed = False
tries = 0
faces = detect(image.filename)
- print("faces found:",len(faces))
+ print("faces found:", len(faces))
while placed is False and tries < 20:
placed = True
x = random.randrange(0, image_size[0] - x_coordinate)
@@ -105,7 +120,7 @@ def randomize_location(image, messages, font): if is_intersected(face, (x, y, x + x_coordinate, y + y_coordinate)):
placed = False
tries = tries + 1
- print("tried:",tries)
+ print("tried:", tries)
return (x, y, len(faces))
|