import time import numpy as np import cv2 as cv import altusi.config as cfg import altusi.visualizer as vis from altusi import imgproc, helper from altusi.logger import Logger from altusi.objectdetector import ObjectDetector LOG = Logger('app-face-detector') def app(video_link, video_name, show, record, flip_hor, flip_ver): # initialize Face Detection net object_detector = ObjectDetector() # initialize Video Capturer cap = cv.VideoCapture(video_link) (W, H), FPS = imgproc.cameraCalibrate(cap) LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS)) if record: time_str = time.strftime(cfg.TIME_FM) writer = cv.VideoWriter(video_name + time_str + '.avi', cv.VideoWriter_fourcc(*'XVID'), 20, (1280, 720)) cnt_frm = 0 while cap.isOpened():
import os import time import numpy as np import cv2 as cv import altusi.config as cfg from altusi import helper, imgproc from altusi.logger import Logger import headvisualizer as hvis import altusi.visualizer as vis from altusi.facedetector import FaceDetector from altusi.headposer import HeadPoser LOG = Logger(__file__.split('.')[0]) def app(video_path, video_name, show=False, record=False): detector = FaceDetector() plugin = detector.getPlugin() poser = HeadPoser(plugin=plugin) cap = cv.VideoCapture(video_path) (W, H), FPS = imgproc.cameraCalibrate(cap) _, frm = cap.read() frm = imgproc.resizeByHeight(frm) H, W = frm.shape[:2] FRM_MOD = int(1. * FPS / cfg.pFPS + 0.5) LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS))
import time import numpy as np import cv2 as cv import altusi.config as cfg import altusi.visualizer as vis from altusi import imgproc, helper from altusi.logger import Logger from altusi.facedetector import FaceDetector from altusi.facelandmarker import FaceLandmarker LOG = Logger('app-face-alignment') h, w = 112., 96. ref_lm_norm = [ 30.2946 / w, 51.6963 / h, 65.5318 / w, 51.5014 / h, 48.0252 / w, 71.7366 / h, 33.5493 / w, 92.3655 / h, 62.7299 / w, 92.2041 / h] def getTransform(src, dst): src = np.array(src, np.float) col_mean_src = np.mean(src, axis=0) src -= col_mean_src dst = np.array(dst, np.float) col_mean_dst = np.mean(dst, axis=0) dst -= col_mean_dst mean, dev_src = cv.meanStdDev(src) dev_src = max(dev_src[0], 1.192e-7) src /= dev_src[0]
import os import time import numpy as np import cv2 as cv from altusi import helper, config as cfg from altusi.logger import Logger from altusi.facedetector import FaceDetector from altusi.facelandmarker import FaceLandmarker from altusi.facealigner import FaceAligner from altusi.faceembedder import FaceEmbedder LOG = Logger('app-face-id') def getDistance(u, v): uv = np.dot(u, v) uu = np.dot(u, u) vv = np.dot(v, v) norm = np.sqrt(uu * vv) + 1e-6 return 1 - uv / norm def app(image1_path, image2_path): # initialize Face detector net detector = FaceDetector() # initialize Face Landmarker net
import time import numpy as np import cv2 as cv import altusi.config as cfg import altusi.visualizer as vis from altusi import imgproc, helper from altusi.logger import Logger from altusi.facedetector import FaceDetector from altusi.emotioner import Emotioner LOG = Logger(__file__.split(',')[0]) EMOTION = ['neutral', 'happy', 'sad', 'surprise', 'anger'] def getPadding(image, bbox): H, W = image.shape[:2] x1, y1, x2, y2 = bbox w, h = x2-x1, y2-y1 if h > w: d = (h - w)/2 x1 = max(0, int(x1 - d)) x2 = min(W, int(x2 + d)) return x1, y1, x2, y2 def app(video_link, video_name, show, record, flip_hor, flip_ver): # initialize Face Detection net
import time import numpy as np import cv2 as cv import altusi.config as cfg import altusi.visualizer as vis from altusi import imgproc, helper from altusi.logger import Logger from altusi.facedetector import FaceDetector from altusi.facelandmarker import FaceLandmarker LOG = Logger('app-landmark-detector') def app(video_link, video_name, show, flip_hor, flip_ver): # initialize Face Detection net face_detector = FaceDetector() LOG.info('Face Detector initialization done') # initialize Face Landmark net face_landmarker = FaceLandmarker() LOG.info('Face Landmarker initialization done') # initialize Video Capturer cap = cv.VideoCapture(video_link) (W, H), FPS = imgproc.cameraCalibrate(cap, size=720, by_height=True) LOG.info('Camera Info: ({}, {}) - {:.3f}'.format(W, H, FPS)) while cap.isOpened(): _, frm = cap.read()
------------- Generate given data (Images and Annotations) to `rec` format """ import os import time import argparse import numpy as np import xml.etree.ElementTree as ET import altusi.config as cfg from altusi.logger import Logger LOG = Logger(__file__.split('.')[0]) def getArgs(): parser = argparse.ArgumentParser() parser.add_argument('--data', '-d', type=str, required=True, help='Path to data folder') parser.add_argument('--name', '-n', type=str, required=False, default='data', help='Name of REC data')
import os import time import numpy as np import mxnet as mx from mxnet import autograd, gluon import gluoncv as gcv from gluoncv.utils import download, viz import altusi.config as cfg from altusi.logger import Logger LOG = Logger(__file__.split('.')[0]) classes = cfg.CLASSES dataset = gcv.data.RecordFileDetection('train-cow.rec') BASE_MODEL = 'ssd_512_mobilenet1.0_custom' TRAINED_MODEL = 'ssd_512_mobilenet1.0_cow.params' BASE_MODEL = 'ssd_512_resnet50_v1_custom' TRAINED_MODEL = 'ssd_512_resnet50_v1_cow.params' #BASE_MODEL = 'ssd_300_vgg16_atrous_custom' #TRAINED_MODEL = 'ssd_300_vgg16_atrous_gym.params' # #BASE_MODEL = 'yolo3_darknet53_custom' #TRAINED_MODEL = 'yolo3_darknet53_gym.params' net = gcv.model_zoo.get_model(BASE_MODEL, classes=classes,
import os import time import numpy as np import cv2 as cv from altusi.logger import Logger from altusi import helper, imgproc import altusi.visualizer as vis from altusi.facedetector import FaceDetector from altusi.facelandmarker import FaceLandmarker LOG = Logger('test-func') TEMPLATE = np.float32([(0.0792396913815, 0.339223741112), (0.0829219487236, 0.456955367943), (0.0967927109165, 0.575648016728), (0.122141515615, 0.691921601066), (0.168687863544, 0.800341263616), (0.239789390707, 0.895732504778), (0.325662452515, 0.977068762493), (0.422318282013, 1.04329000149), (0.531777802068, 1.06080371126), (0.641296298053, 1.03981924107), (0.738105872266, 0.972268833998), (0.824444363295, 0.889624082279), (0.894792677532, 0.792494155836), (0.939395486253, 0.681546643421), (0.96111933829, 0.562238253072), (0.970579841181, 0.441758925744),
import time import numpy as np import cv2 as cv import altusi.config as cfg import altusi.visualizer as vis from altusi import imgproc, helper from altusi.logger import Logger from altusi.facedetector import FaceDetector from altusi.emotioner import Emotioner LOG = Logger(__file__.split(',')[0]) def app(image_path): # initialize Face Detection net face_detector = FaceDetector() # initialize Emotioner net emotioner = Emotioner() frm = cv.imread(image_path) _start_t = time.time() scores, bboxes = face_detector.getFaces(frm, def_score=0.5) for i, bbox in enumerate(bboxes): x1, y1, x2, y2 = bbox face_img = frm[y1:y2, x1:x2] emo_idx = emotioner.getEmotion(face_img) LOG.info('emotion: {}'.format(emo_idx)) _prx_t = time.time() - _start_t