The previous commit broke for pyhton2 but fixed python3. This should deal with

numpy's import_array() in a more robust way.
This commit is contained in:
Davis King 2017-12-09 20:52:07 -05:00
parent 7b38ea6f2d
commit be8269900c
3 changed files with 20 additions and 9 deletions

View File

@ -21,7 +21,7 @@ void bind_correlation_tracker();
void bind_face_recognition();
void bind_cnn_face_detection();
void bind_global_optimization();
void* bind_numpy_returns();
void bind_numpy_returns();
#ifndef DLIB_NO_GUI_SUPPORT
void bind_gui();

View File

@ -125,10 +125,25 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(get_face_chips_with_defaults, get_face_chips, 2,
// ----------------------------------------------------------------------------------------
void* bind_numpy_returns()
// we need this wonky stuff because different versions of numpy's import_array macro
// contain differently typed return statements inside import_array().
#if PY_VERSION_HEX >= 0x03000000
#define DLIB_NUMPY_IMPORT_ARRAY_RETURN_TYPE void*
#define DLIB_NUMPY_IMPORT_RETURN return 0
#else
#define DLIB_NUMPY_IMPORT_ARRAY_RETURN_TYPE void
#define DLIB_NUMPY_IMPORT_RETURN return
#endif
DLIB_NUMPY_IMPORT_ARRAY_RETURN_TYPE import_numpy_stuff()
{
import_array();
DLIB_NUMPY_IMPORT_RETURN;
}
void bind_numpy_returns()
{
using boost::python::arg;
import_array();
import_numpy_stuff();
def("jitter_image", &get_jitter_images, get_jitter_images_with_defaults(
"Takes an image and returns a list of jittered images."
@ -146,6 +161,4 @@ void* bind_numpy_returns()
"Takes an image and a full_object_detections object that reference faces in that image and returns the faces as a list of Numpy arrays representing the image. The faces will be rotated upright and scaled to 150x150 pixels or with the optional specified size and padding.",
(arg("img"), arg("faces"), arg("size"), arg("padding"))
));
return 0;
}

View File

@ -44,7 +44,7 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(get_face_chips_with_defaults, get_face_chips, 2,
// ----------------------------------------------------------------------------------------
void* bind_numpy_returns()
void bind_numpy_returns()
{
using boost::python::arg;
@ -64,6 +64,4 @@ void* bind_numpy_returns()
"Takes an image and a full_object_detections object that reference faces in that image and returns the faces as a list of Numpy arrays representing the image. The faces will be rotated upright and scaled to 150x150 pixels or with the optional specified size and padding.",
(arg("img"), arg("faces"), arg("size"), arg("padding"))
));
return 0;
}
}