From f9fc180e1abc5a0f209635ab1f476aa7d91e38fa Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Fri, 10 Jun 2011 17:22:33 +0000 Subject: [PATCH] fixed tickets #1117 and #954 --- modules/ml/src/em.cpp | 2 +- modules/python/src1/cv.cpp | 11 +++++------ modules/python/src2/cv2.cpp | 10 ++++++---- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/ml/src/em.cpp b/modules/ml/src/em.cpp index 63d833a..4843696 100644 --- a/modules/ml/src/em.cpp +++ b/modules/ml/src/em.cpp @@ -1284,7 +1284,7 @@ void CvEM::getCovs(vector& _covs) const int i, n = params.nclusters; _covs.resize(n); for( i = 0; i < n; i++ ) - _covs[i] = Mat(covs[i]); + Mat(covs[i]).copyTo(_covs[i]); } Mat CvEM::getWeights() const diff --git a/modules/python/src1/cv.cpp b/modules/python/src1/cv.cpp index dfd082b..ae75e0a 100644 --- a/modules/python/src1/cv.cpp +++ b/modules/python/src1/cv.cpp @@ -2860,10 +2860,6 @@ static PyObject *fromarray(PyObject *o, int allowND) type = CV_16SC1; else if (pai->itemsize == 4) type = CV_32SC1; - else if (pai->itemsize == 8) { - PyErr_SetString(PyExc_TypeError, "OpenCV cannot handle 64-bit integer arrays"); - return NULL; - } break; case 'u': @@ -2879,9 +2875,12 @@ static PyObject *fromarray(PyObject *o, int allowND) else if (pai->itemsize == 8) type = CV_64FC1; break; - + + } + if (type == -1) { + PyErr_SetString(PyExc_TypeError, "the array type is not supported by OpenCV"); + return NULL; } - assert(type != -1); if (!allowND) { cvmat_t *m = PyObject_NEW(cvmat_t, &cvmat_Type); diff --git a/modules/python/src2/cv2.cpp b/modules/python/src2/cv2.cpp index e9c2aa4..f9cfde4 100644 --- a/modules/python/src2/cv2.cpp +++ b/modules/python/src2/cv2.cpp @@ -237,7 +237,7 @@ static PyObject* pyopencv_from(const Mat& m) Mat temp, *p = (Mat*)&m; if(!p->refcount || p->allocator != &g_numpyAllocator) { - pyopencv_to(Py_None, temp); + temp.allocator = &g_numpyAllocator; m.copyTo(temp); p = &temp; } @@ -484,7 +484,7 @@ template struct pyopencvVecConverter static bool to(PyObject* obj, vector<_Tp>& value, const char* name="") { typedef typename DataType<_Tp>::channel_type _Cp; - if(!obj) + if(!obj || obj == Py_None) return true; if (PyArray_Check(obj)) { @@ -596,6 +596,8 @@ static PyObject* pyopencv_from(const KeyPoint&); template static inline bool pyopencv_to_generic_vec(PyObject* obj, vector<_Tp>& value, const char* name="") { + if(!obj || obj == Py_None) + return true; if (!PySequence_Check(obj)) return false; PyObject *seq = PySequence_Fast(obj, name); @@ -619,13 +621,13 @@ template static inline bool pyopencv_to_generic_vec(PyObject* obj, template static inline PyObject* pyopencv_from_generic_vec(const vector<_Tp>& value) { int i, n = (int)value.size(); - PyObject* seq = PyTuple_New(n); + PyObject* seq = PyList_New(n); for( i = 0; i < n; i++ ) { PyObject* item = pyopencv_from(value[i]); if(!item) break; - PyTuple_SET_ITEM(seq, i, item); + PyList_SET_ITEM(seq, i, item); } if( i < n ) { -- 2.7.4