mirror of
https://github.com/opencv/opencv.git
synced 2024-12-01 06:49:50 +08:00
Python wrappers for Vec and Matx
This commit is contained in:
parent
513c2b92a4
commit
868ad16041
@ -394,6 +394,24 @@ bool pyopencv_to(PyObject* o, Mat& m, const char* name)
|
||||
return pyopencv_to(o, m, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
template<typename _Tp, int m, int n>
|
||||
bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const ArgInfo info)
|
||||
{
|
||||
Mat tmp;
|
||||
if (!pyopencv_to(o, tmp, info)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
tmp.copyTo(mx);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename _Tp, int m, int n>
|
||||
bool pyopencv_to(PyObject* o, Matx<_Tp, m, n>& mx, const char* name)
|
||||
{
|
||||
return pyopencv_to(o, mx, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool pyopencv_to(PyObject *o, Ptr<T>& p, const char *name)
|
||||
{
|
||||
@ -681,18 +699,17 @@ PyObject* pyopencv_from(const UMat& m) {
|
||||
return o;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, Scalar& s, const char *name)
|
||||
static bool pyopencv_to(PyObject *o, Scalar& s, const ArgInfo info)
|
||||
{
|
||||
if(!o || o == Py_None)
|
||||
return true;
|
||||
if (PySequence_Check(o)) {
|
||||
PyObject *fi = PySequence_Fast(o, name);
|
||||
PyObject *fi = PySequence_Fast(o, info.name);
|
||||
if (fi == NULL)
|
||||
return false;
|
||||
if (4 < PySequence_Fast_GET_SIZE(fi))
|
||||
{
|
||||
failmsg("Scalar value for argument '%s' is longer than 4", name);
|
||||
failmsg("Scalar value for argument '%s' is longer than 4", info.name);
|
||||
return false;
|
||||
}
|
||||
for (Py_ssize_t i = 0; i < PySequence_Fast_GET_SIZE(fi); i++) {
|
||||
@ -700,7 +717,7 @@ bool pyopencv_to(PyObject *o, Scalar& s, const char *name)
|
||||
if (PyFloat_Check(item) || PyInt_Check(item)) {
|
||||
s[(int)i] = PyFloat_AsDouble(item);
|
||||
} else {
|
||||
failmsg("Scalar value for argument '%s' is not numeric", name);
|
||||
failmsg("Scalar value for argument '%s' is not numeric", info.name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -709,13 +726,19 @@ bool pyopencv_to(PyObject *o, Scalar& s, const char *name)
|
||||
if (PyFloat_Check(o) || PyInt_Check(o)) {
|
||||
s[0] = PyFloat_AsDouble(o);
|
||||
} else {
|
||||
failmsg("Scalar value for argument '%s' is not numeric", name);
|
||||
failmsg("Scalar value for argument '%s' is not numeric", info.name);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
bool pyopencv_to(PyObject *o, Scalar& s, const char *name)
|
||||
{
|
||||
return pyopencv_to(o, s, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Scalar& src)
|
||||
{
|
||||
@ -1022,13 +1045,139 @@ PyObject* pyopencv_from(const Point3f& p)
|
||||
return Py_BuildValue("(ddd)", p.x, p.y, p.z);
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec4d& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "dddd", &v[0], &v[1], &v[2], &v[3]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec4d& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec4f& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ffff", &v[0], &v[1], &v[2], &v[3]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec4f& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec4i& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "iiii", &v[0], &v[1], &v[2], &v[3]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec4i& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec3d& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ddd", &v[0], &v[1], &v[2]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec3d& v, const char* name)
|
||||
{
|
||||
(void)name;
|
||||
if(!obj)
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec3f& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ddd", &v[0], &v[1], &v[2]) > 0;
|
||||
return PyArg_ParseTuple(obj, "fff", &v[0], &v[1], &v[2]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec3f& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec3i& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "iii", &v[0], &v[1], &v[2]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec3i& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec2d& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "dd", &v[0], &v[1]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec2d& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec2f& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ff", &v[0], &v[1]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec2f& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
static bool pyopencv_to(PyObject* obj, Vec2i& v, ArgInfo info)
|
||||
{
|
||||
(void)info;
|
||||
if (!obj)
|
||||
return true;
|
||||
return PyArg_ParseTuple(obj, "ii", &v[0], &v[1]) > 0;
|
||||
}
|
||||
template<>
|
||||
bool pyopencv_to(PyObject* obj, Vec2i& v, const char* name)
|
||||
{
|
||||
return pyopencv_to(obj, v, ArgInfo(name, 0));
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec4d& v)
|
||||
{
|
||||
return Py_BuildValue("(dddd)", v[0], v[1], v[2], v[3]);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec4f& v)
|
||||
{
|
||||
return Py_BuildValue("(ffff)", v[0], v[1], v[2], v[3]);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec4i& v)
|
||||
{
|
||||
return Py_BuildValue("(iiii)", v[0], v[1], v[2], v[3]);
|
||||
}
|
||||
|
||||
template<>
|
||||
@ -1037,12 +1186,36 @@ PyObject* pyopencv_from(const Vec3d& v)
|
||||
return Py_BuildValue("(ddd)", v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec3f& v)
|
||||
{
|
||||
return Py_BuildValue("(fff)", v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec3i& v)
|
||||
{
|
||||
return Py_BuildValue("(iii)", v[0], v[1], v[2]);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec2d& v)
|
||||
{
|
||||
return Py_BuildValue("(dd)", v[0], v[1]);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec2f& v)
|
||||
{
|
||||
return Py_BuildValue("(ff)", v[0], v[1]);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Vec2i& v)
|
||||
{
|
||||
return Py_BuildValue("(ii)", v[0], v[1]);
|
||||
}
|
||||
|
||||
template<>
|
||||
PyObject* pyopencv_from(const Point2d& p)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user