Commit be826990 authored by Davis King's avatar Davis King

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

numpy's import_array() in a more robust way.
parent 7b38ea6f
......@@ -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();
......
......@@ -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()
{
using boost::python::arg;
import_array();
DLIB_NUMPY_IMPORT_RETURN;
}
void bind_numpy_returns()
{
using boost::python::arg;
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;
}
......@@ -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;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment