Commit 15207aad authored by Davis King's avatar Davis King

Added another python utility. This one deserializes objects.

parent 7edb820b
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <boost/python.hpp> #include <boost/python.hpp>
#include <vector> #include <vector>
#include <string> #include <string>
#include <dlib/serialize.h>
inline bool hasattr( inline bool hasattr(
boost::python::object obj, boost::python::object obj,
...@@ -58,6 +59,25 @@ boost::python::list vector_to_python_list ( ...@@ -58,6 +59,25 @@ boost::python::list vector_to_python_list (
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T>
boost::shared_ptr<T> load_object_from_file (
const std::string& filename
)
/*!
ensures
- deserializes an object of type T from the given file and returns it.
!*/
{
std::ifstream fin(filename.c_str(), std::ios::binary);
if (!fin)
throw dlib::error("Unable to open " + filename);
boost::shared_ptr<T> obj(new T());
deserialize(*obj, fin);
return obj;
}
// ----------------------------------------------------------------------------------------
#endif // DLIB_BOOST_PYTHON_UtILS_H__ #endif // DLIB_BOOST_PYTHON_UtILS_H__
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