hassan526's picture
Upload 40 files
25b4c0f verified
Raw History Blame Contribute Delete
1.82 kB
import os
import sys
import numpy as np
import ctypes, ctypes.util
from enum import Enum
from ctypes import *
from numpy.ctypeslib import ndpointer
def print_log(fmt): print("[LOG] \033[98m{}\033[00m" .format(fmt))
def print_info(fmt): print("[INFO] \033[92m{}\033[00m" .format(fmt))
def print_error(fmt): print("[ERR] \033[91m{}\033[00m" .format(fmt))
def print_warning(fmt): print("[WARNING] \033[93m{}\033[00m" .format(fmt))
class ENGINE_CODE(Enum):
E_NO_FACE = 0
E_ACTIVATION_ERROR = -1
E_ENGINE_INIT_ERROR = -2
class Face(Structure):
_fields_ = [("x", c_int32), ("y", c_int32), ("width", c_int32), ("height", c_int32),
("yaw", c_float), ("roll", c_float), ("pitch", c_float),
("age", c_int32), ("gender", c_int32),
("neutral", c_float), ("happy", c_float), ("angry", c_float),
("surprised", c_float), ("disgusted", c_float), ("sad", c_float), ("scared", c_float),
("masked", c_int32), ("left_eye_opened", c_int32), ("right_eye_opened", c_int32),
("featSize", c_int32),
("featData", c_ubyte * 512)
]
libPath = os.path.abspath(os.path.dirname(__file__)) + '/libopyfacerecog.so'
lib = cdll.LoadLibrary(libPath)
getHWID = lib.getHWID
getHWID.argtypes = []
getHWID.restype = c_char_p
setLicenseKey = lib.setLicenseKey
setLicenseKey.argtypes = [c_char_p]
setLicenseKey.restype = c_int32
initSDK = lib.initSDK
initSDK.argtypes = [c_char_p]
initSDK.restype = c_int32
processImage = lib.processImage
processImage.argtypes = [ndpointer(c_ubyte, flags='C_CONTIGUOUS'), c_int32, c_int32, POINTER(Face), c_int32]
processImage.restype = c_int32
verifyFeat = lib.verifyFeat
verifyFeat.argtypes = [c_int32, c_ubyte * 512, c_int32, c_ubyte * 512]
verifyFeat.restype = c_float