Browse Source

chore(logging): replace print statements with logging

pull/5/head
the-wastl 5 years ago
parent
commit
844dee83e8
2 changed files with 16 additions and 6 deletions
  1. +11
    -4
      main.py
  2. +5
    -2
      mods/__init__.py

+ 11
- 4
main.py View File

@@ -9,6 +9,7 @@
import sys

import cv2
import logging
import numpy as np
import random as rd
import os
@@ -19,6 +20,12 @@ from datetime import datetime

ESCAPE_KEY = 27

logging.basicConfig(level=logging.INFO,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s',
datefmt='%m-%d %H:%M')

logger = logging.getLogger("main")
logger.setLevel(logging.INFO)

# The following function is used to determine the placement of
# text, at the moment it is incomplete
@@ -51,7 +58,7 @@ def add_elements(img):
# create a set to prevent element repetition
added_counter = 0

print("Adding %d elements" % (num_elements, ))
logger.info("Adding %d elements" % (num_elements, ))

for file_name in map(partial(os.path.join, base_dir), all_files):
if added_counter == num_elements:
@@ -66,7 +73,7 @@ def add_single_element(img, file_name):
imh, imw, imd = img.shape
element = cv2.imread(file_name, -1)
if element is None:
print("Could not read file %s" % (file_name,))
logger.warning("Could not read file %s" % (file_name,))
return False

original_height, original_width, original_depth = element.shape
@@ -77,7 +84,7 @@ def add_single_element(img, file_name):
resized_height, resized_width, _ = element.shape
# refuse to use this image, if this failed
if resized_height > imh or resized_width > imw:
print("Element %s too big, moving on" % (file_name,))
logger.warning("Element %s too big, moving on" % (file_name,))
return False
# get x coord and y coord on the image
from_x_pos = rd.randint(1, imw - resized_width - 1)
@@ -117,7 +124,7 @@ def main():
img = vaporize()
cv2.imshow("pic", img)
end = time.time()
print("Vaporizing and rendering took: %f seconds" % (end-start,))
logger.info("Vaporizing and rendering took: %f seconds" % (end-start,))
cv2.destroyAllWindows()
sys.exit()


+ 5
- 2
mods/__init__.py View File

@@ -1,6 +1,7 @@
import math

import cv2
import logging
import numpy as np
import random as rd

@@ -13,6 +14,8 @@ EYE_DRAG = 4
EYES = 100
FACE = 101

logger = logging.getLogger("mods")


def determine_face_mod(eyes_present):
function_list = [
@@ -66,7 +69,7 @@ def eye_drag(img, eyes):

def eye_censor(img, eyes):
if len(eyes) < 2:
print("Failed to generate censor, less than two eyes present")
logger.warning("Failed to generate censor, less than two eyes present")
return
# cenH = 40
# get centroids of eyes
@@ -173,7 +176,7 @@ def face_glitch(img, face):
old = img[face[1] + (itr * strp):face[1] + (itr * strp + strp), back_bound:left_ext]
new = img[face[1] + (itr * strp):face[1] + (itr * strp + strp), face[0]:face[0] + face[2] - diff]
if old.shape != new.shape:
print("Shape mismatch: %s vs %s" % (old.shape, new.shape, ))
logger.warning("Shape mismatch: %s vs %s" % (old.shape, new.shape, ))
return

img[face[1] + (itr * strp):face[1] + (itr * strp + strp), back_bound:left_ext] = \

Loading…
Cancel
Save