--- C:/DOCUME~1/mbaker/LOCALS~1/Temp/cv.cp-rev16585.svn001.tmp.cpp Fri Jun 17 08:06:35 2011 +++ C:/DOCUME~1/mbaker/LOCALS~1/Temp/cv.cp-rev16595.svn001.tmp.cpp Fri Jun 17 08:06:36 2011 @@ -694,6 +694,8 @@ { cvmatnd_t *pc = (cvmatnd_t*)self; Py_DECREF(pc->data); + cvDecRefData(pc->a); + cvFree(&pc->a); PyObject_Del(self); } @@ -2786,6 +2788,7 @@ static PyObject *fromarray(PyObject *o, int allowND) { + PyObject *retval; PyObject *ao = PyObject_GetAttrString(o, "__array_struct__"); if ((ao == NULL) || !PyCObject_Check(ao)) { PyErr_SetString(PyExc_TypeError, "object does not have array interface"); @@ -2794,7 +2797,8 @@ PyArrayInterface *pai = (PyArrayInterface*)PyCObject_AsVoidPtr(ao); if (pai->two != 2) { PyErr_SetString(PyExc_TypeError, "object does not have array interface"); - return NULL; + Py_DECREF(ao); + return NULL; } int type = -1; @@ -2809,7 +2813,8 @@ type = CV_32SC1; else if (pai->itemsize == 8) { PyErr_SetString(PyExc_TypeError, "OpenCV cannot handle 64-bit integer arrays"); - return NULL; + Py_DECREF(ao); + return NULL; } break; @@ -2834,20 +2839,27 @@ cvmat_t *m = PyObject_NEW(cvmat_t, &cvmat_Type); if (pai->nd == 2) { if (pai->strides[1] != pai->itemsize) { + Py_DECREF(ao); return (PyObject*)failmsg("cv.fromarray array can only accept arrays with contiguous data"); } ERRWRAP(m->a = cvCreateMatHeader(pai->shape[0], pai->shape[1], type)); m->a->step = pai->strides[0]; } else if (pai->nd == 3) { - if (pai->shape[2] > CV_CN_MAX) - return (PyObject*)failmsg("cv.fromarray too many channels, see allowND argument"); + if (pai->shape[2] > CV_CN_MAX){ + Py_DECREF(ao); + return (PyObject*)failmsg("cv.fromarray too many channels, see allowND argument"); + } ERRWRAP(m->a = cvCreateMatHeader(pai->shape[0], pai->shape[1], type + ((pai->shape[2] - 1) << CV_CN_SHIFT))); m->a->step = pai->strides[0]; } else { + Py_DECREF(ao); return (PyObject*)failmsg("cv.fromarray array can be 2D or 3D only, see allowND argument"); } m->a->data.ptr = (uchar*)pai->data; - return pythonize_foreign_CvMat(m); + m->data = o; + m->offset = 0; + retval = (PyObject*) m;//pythonize_foreign_CvMat(m); + //dont call their function as it leaks and foreign memory should not be managed by OpenCV } else { int dims[CV_MAX_DIM]; int i; @@ -2856,8 +2868,14 @@ cvmatnd_t *m = PyObject_NEW(cvmatnd_t, &cvmatnd_Type); ERRWRAP(m->a = cvCreateMatND(pai->nd, dims, type)); m->a->data.ptr = (uchar*)pai->data; - return pythonize_CvMatND(m); + m->data = o; + m->offset = 0; + retval = (PyObject*) m; //pythonize_CvMatND(m); + //dont call their function as it leaks and foreign memory should not be managed by OpenCV } + Py_DECREF(ao); + Py_INCREF(o); + return retval; } #endif