Skip to content

Instantly share code, notes, and snippets.

@aroman
Created February 3, 2017 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aroman/42dcc36a2485c792b205c50ccf95091d to your computer and use it in GitHub Desktop.
Save aroman/42dcc36a2485c792b205c50ccf95091d to your computer and use it in GitHub Desktop.
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();
}
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