|
|
@ -5,6 +5,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "cv2_convert.hpp" |
|
|
|
#include "cv2_convert.hpp" |
|
|
|
#include "cv2_numpy.hpp" |
|
|
|
#include "cv2_numpy.hpp" |
|
|
|
|
|
|
|
#include "cv2_util.hpp" |
|
|
|
#include "opencv2/core/utils/logger.hpp" |
|
|
|
#include "opencv2/core/utils/logger.hpp" |
|
|
|
|
|
|
|
|
|
|
|
PyTypeObject* pyopencv_Mat_TypePtr = nullptr; |
|
|
|
PyTypeObject* pyopencv_Mat_TypePtr = nullptr; |
|
|
@ -24,6 +25,26 @@ static std::string pycv_dumpArray(const T* arr, int n) |
|
|
|
return out.str(); |
|
|
|
return out.str(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static inline std::string getArrayTypeName(PyArrayObject* arr) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
PyArray_Descr* dtype = PyArray_DESCR(arr); |
|
|
|
|
|
|
|
PySafeObject dtype_str(PyObject_Str(reinterpret_cast<PyObject*>(dtype))); |
|
|
|
|
|
|
|
if (!dtype_str) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Fallback to typenum value
|
|
|
|
|
|
|
|
return cv::format("%d", PyArray_TYPE(arr)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::string type_name; |
|
|
|
|
|
|
|
if (!getUnicodeString(dtype_str, type_name)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
// Failed to get string from bytes object - clear set TypeError and
|
|
|
|
|
|
|
|
// fallback to typenum value
|
|
|
|
|
|
|
|
PyErr_Clear(); |
|
|
|
|
|
|
|
return cv::format("%d", PyArray_TYPE(arr)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return type_name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//======================================================================================================================
|
|
|
|
//======================================================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
// --- Mat
|
|
|
|
// --- Mat
|
|
|
@ -102,7 +123,9 @@ bool pyopencv_to(PyObject* o, Mat& m, const ArgInfo& info) |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
failmsg("%s data type = %d is not supported", info.name, typenum); |
|
|
|
const std::string dtype_name = getArrayTypeName(oarr); |
|
|
|
|
|
|
|
failmsg("%s data type = %s is not supported", info.name, |
|
|
|
|
|
|
|
dtype_name.c_str()); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|