Created
February 3, 2017 08:06
-
-
Save aroman/42dcc36a2485c792b205c50ccf95091d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void mxnet_detect(const cv::Mat& mat) { | |
PyObject *pRunnerModule, *pRunnerFunc, *pRunnerResult; | |
Py_SetProgramName("mtcnn-bridge"); | |
Py_Initialize(); | |
PyEval_InitThreads(); | |
import_array(); | |
Py_BEGIN_ALLOW_THREADS | |
PyObject* moduleName = PyString_FromString((char*)"mtcnn_runner"); | |
pRunnerModule = PyImport_Import(moduleName); | |
pRunnerFunc = PyObject_GetAttrString(pRunnerModule,(char*)"detect"); | |
npyIntp dims[] = {1080,1920,3}; | |
PyObject *pArray = PyArraySimpleNewFromData(3, dims, NPYUINT8, mat.data); | |
PyObject *arglist = Py_BuildValue("(O)", pArray); | |
pRunnerResult = PyObject_CallObject(pRunnerFunc, arglist); | |
Py_END_ALLOW_THREADS | |
Py_Finalize(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
from pprint import pprint as pp | |
import mxnet as mx | |
from mtcnn_detector import MtcnnDetector | |
detector = MtcnnDetector(model_folder='model', ctx=mx.cpu(0), num_worker = 1 , accurate_landmark = False) | |
def detect(img): | |
# somehere inside detect_face, a threadpool is used | |
# specifically, the built-in multi-threading library and the Pool.map function | |
results = detector.detect_face(img) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment