text stringlengths 0 93.6k |
|---|
elif portion > 1: |
#landscape |
if portion >= 1.3333: |
pic_h = 960 |
pic_w = round(960*portion) |
box = (round((pic_w-1280)/2),0,round(pic_w/2+640),960) |
if portion < 1.3333: |
pic_w = 1280 |
pic_h = round(1280/portion) |
box = (0,round((pic_h-960)/2),1280,round(pic_h/2+480)) |
elif portion == 1: |
#square |
(pic_w,pic_h) = (960,960) |
box = (0,0,960,960) |
pic = pic.resize((pic_w, pic_h)) |
pic = pic.crop(box) |
return pic |
def facedet(pil_image): |
#input an PIL Image object and output a list of positions of faces |
# Create the haar cascade |
cascPath = './xmas/haarcascade_frontalface_default.xml' |
faceCascade = cv2.CascadeClassifier(cascPath) |
# Read the image |
#image = cv2.imread(imagePath) |
#pil_image = std_size(imagePath) |
image = cv2.cvtColor(numpy.array(pil_image), cv2.COLOR_RGB2BGR) |
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) |
# Detect faces in the image |
faces = faceCascade.detectMultiScale( |
gray, |
scaleFactor=1.2, |
minNeighbors=5, |
minSize=(50, 60), |
flags=cv2.CASCADE_SCALE_IMAGE |
) |
# Draw a rectangle around the faces |
#for (x, y, w, h) in faces: |
# cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2) |
#cv2.imwrite(o_path, image) |
return faces |
imagePath = os.path.join('media', MediaId) |
o_path = os.path.join('media', MediaId + '.jpg') |
image = std_size(imagePath) |
faces = facedet(image) |
for (x,y,w,h) in faces: |
print('face at:',x,y,w,h) |
#draw = ImageDraw.Draw(image) |
#draw.rectangle([(x, y), (x+w, y+h)]) |
(hatter,hat_pos) = get_hat(x,y,w,h) |
image.paste(hatter, hat_pos, hatter) |
#add photo to the frame |
portion = image.size[0]/image.size[1] |
if portion > 1: |
image.paste(frame_w, (0,0), frame_w) |
elif portion < 1: |
image.paste(frame_h, (0,0), frame_h) |
else: |
image.paste(frame_s, (0,0), frame_s) |
image.save(o_path) |
# <FILESEP> |
from flask import Flask, render_template, redirect, url_for, request |
import subprocess |
import logging |
from logging.handlers import RotatingFileHandler |
from flask_cors import CORS |
from flask_caching import Cache |
from main import further_classifier |
app = Flask(__name__) |
CORS(app) |
cache = Cache(app, config={'CACHE_TYPE': 'simple', 'CACHE_TIMEOUT':1800}) |
handler = RotatingFileHandler('error.log', maxBytes=10000, backupCount=1) |
handler.setLevel(logging.ERROR) |
app.logger.addHandler(handler) |
@app.route('/') |
def index(): |
return render_template('index.html') |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.