File size: 1,815 Bytes
25b4c0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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