cv.cpp_patch_for_ticket_993.diff

Matthew Baker, 2011-06-17 12:15 am

Download (3 kB)

 
C:/DOCUME~1/mbaker/LOCALS~1/Temp/cv.cp-rev16595.svn001.tmp.cpp Fri Jun 17 08:06:36 2011
694 694
{
695 695
  cvmatnd_t *pc = (cvmatnd_t*)self;
696 696
  Py_DECREF(pc->data);
697
  cvDecRefData(pc->a);
698
  cvFree(&pc->a);
697 699
  PyObject_Del(self);
698 700
}
699 701

  
......
2786 2788

  
2787 2789
static PyObject *fromarray(PyObject *o, int allowND)
2788 2790
{
2791
  PyObject *retval;
2789 2792
  PyObject *ao = PyObject_GetAttrString(o, "__array_struct__");
2790 2793
  if ((ao == NULL) || !PyCObject_Check(ao)) {
2791 2794
    PyErr_SetString(PyExc_TypeError, "object does not have array interface");
......
2794 2797
  PyArrayInterface *pai = (PyArrayInterface*)PyCObject_AsVoidPtr(ao);
2795 2798
  if (pai->two != 2) {
2796 2799
    PyErr_SetString(PyExc_TypeError, "object does not have array interface");
2797
    return NULL;
2800
    Py_DECREF(ao);
2801
	return NULL;
2798 2802
  }
2799 2803

  
2800 2804
  int type = -1;
......
2809 2813
      type = CV_32SC1;
2810 2814
    else if (pai->itemsize == 8) {
2811 2815
      PyErr_SetString(PyExc_TypeError, "OpenCV cannot handle 64-bit integer arrays");
2812
      return NULL;
2816
      Py_DECREF(ao);
2817
	  return NULL;
2813 2818
    }
2814 2819
    break;
2815 2820

  
......
2834 2839
    cvmat_t *m = PyObject_NEW(cvmat_t, &cvmat_Type);
2835 2840
    if (pai->nd == 2) {
2836 2841
      if (pai->strides[1] != pai->itemsize) {
2842
	    Py_DECREF(ao);
2837 2843
        return (PyObject*)failmsg("cv.fromarray array can only accept arrays with contiguous data");
2838 2844
      }
2839 2845
      ERRWRAP(m->a = cvCreateMatHeader(pai->shape[0], pai->shape[1], type));
2840 2846
      m->a->step = pai->strides[0];
2841 2847
    } else if (pai->nd == 3) {
2842
      if (pai->shape[2] > CV_CN_MAX)
2843
        return (PyObject*)failmsg("cv.fromarray too many channels, see allowND argument");
2848
		if (pai->shape[2] > CV_CN_MAX){
2849
			Py_DECREF(ao);
2850
			return (PyObject*)failmsg("cv.fromarray too many channels, see allowND argument");
2851
		}
2844 2852
      ERRWRAP(m->a = cvCreateMatHeader(pai->shape[0], pai->shape[1], type + ((pai->shape[2] - 1) << CV_CN_SHIFT)));
2845 2853
      m->a->step = pai->strides[0];
2846 2854
    } else {
2855
	  Py_DECREF(ao);
2847 2856
      return (PyObject*)failmsg("cv.fromarray array can be 2D or 3D only, see allowND argument");
2848 2857
    }
2849 2858
    m->a->data.ptr = (uchar*)pai->data;
2850
    return pythonize_foreign_CvMat(m);
2859
    m->data = o;
2860
    m->offset = 0;
2861
    retval = (PyObject*) m;//pythonize_foreign_CvMat(m);
2862
    //dont call their function as it leaks and foreign memory should not be managed by OpenCV
2851 2863
  } else {
2852 2864
    int dims[CV_MAX_DIM];
2853 2865
    int i;
......
2856 2868
    cvmatnd_t *m = PyObject_NEW(cvmatnd_t, &cvmatnd_Type);
2857 2869
    ERRWRAP(m->a = cvCreateMatND(pai->nd, dims, type));
2858 2870
    m->a->data.ptr = (uchar*)pai->data;
2859
    return pythonize_CvMatND(m);
2871
	m->data = o;
2872
	m->offset = 0;
2873
    retval = (PyObject*) m; //pythonize_CvMatND(m);
2874
	//dont call their function as it leaks and foreign memory should not be managed by OpenCV
2860 2875
  }
2876
  Py_DECREF(ao);
2877
  Py_INCREF(o);
2878
  return retval;
2861 2879
}
2862 2880
#endif
2863 2881