]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
Partial fix for #150
authorjamesb <jamesb@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Tue, 9 Mar 2010 21:55:43 +0000 (21:55 +0000)
committerjamesb <jamesb@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Tue, 9 Mar 2010 21:55:43 +0000 (21:55 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@2763 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/interfaces/python/cv.cpp
opencv/tests/python/test.py

index 2426b1f2af1729d1949b99f80d07a90946ccacfc..f8569cdd38abf0b7888249f77e87cfabb84a7f6e 100644 (file)
@@ -3284,6 +3284,57 @@ static PyObject *pycvReshape(PyObject *self, PyObject *args)
   return (PyObject*)om;
 }
 
+static PyObject *pycvReshapeMatND(PyObject *self, PyObject *args)
+{
+  PyObject *o;
+  int new_cn;
+  PyObject *new_dims;
+
+  if (!PyArg_ParseTuple(args, "OiO", &o, &new_cn, &new_dims))
+    return NULL;
+
+  CvMatND *cva;
+  if (!convert_to_CvMatND(o, &cva, "src"))
+    return NULL;
+  ints dims;
+  if (!convert_to_ints(new_dims, &dims, "new_dims"))
+    return NULL;
+  int dummy[1] = { 1 };
+
+#if 0
+  CvMatND *m = cvCreateMatNDHeader(1, dummy, 1); // these args do not matter, because overwritten
+  ERRWRAP(cvReshapeND(cva, m, new_cn, dims.count + 1, dims.i));
+
+  cvmatnd_t *om = PyObject_NEW(cvmatnd_t, &cvmatnd_Type);
+  om->a = m;
+  om->data = what_data(o);
+  Py_INCREF(om->data);
+  om->offset = 0;
+  return (PyObject*)om;
+#endif
+#if 0
+  CvMat *m = cvCreateMatHeader(100, 100, 1); // these args do not matter, because overwritten
+  ERRWRAP(cvReshapeND(cva, m, 0, 1, 0)); // new_cn, dims.count + 1, dims.i));
+
+  cvmat_t *om = PyObject_NEW(cvmat_t, &cvmat_Type);
+  om->a = m;
+  om->data = what_data(o);
+  Py_INCREF(om->data);
+  om->offset = 0;
+  return (PyObject*)om;
+#endif
+#if 1
+  {
+    int size[] = { 2, 2, 2 };
+    CvMatND* mat = cvCreateMatND(3, size, CV_32F);
+    CvMat row_header;
+    CvArr *row;
+    row = cvReshapeND(mat, &row_header, 0, 1, 0);
+  }
+  Py_RETURN_NONE;
+#endif
+}
+
 static void OnMouse(int event, int x, int y, int flags, void* param)
 {
   PyGILState_STATE gstate;
@@ -3816,6 +3867,7 @@ static PyMethodDef methods[] = {
   {"GetImage", pycvGetImage, METH_VARARGS, "GetImage(cvmat) -> image"},
   {"GetMat", (PyCFunction)pycvGetMat, METH_KEYWORDS, "GetMat(image, allowND=0) -> cvmat"},
   {"Reshape", pycvReshape, METH_VARARGS, "Reshape(arr, new_cn, new_rows=0) -> cvmat"},
+  {"ReshapeMatND", pycvReshapeMatND, METH_VARARGS, "Reshape(arr, new_cn, new_dims) -> matnd"},
   {"InitLineIterator", pycvInitLineIterator, METH_VARARGS, "InitLineIterator(image, pt1, pt2, connectivity=8, left_to_right=0) -> None"},
   {"LoadImage", (PyCFunction)pycvLoadImage, METH_KEYWORDS, "LoadImage(filename, iscolor=CV_LOAD_IMAGE_COLOR)"},
   {"SetData", pycvSetData, METH_VARARGS, "SetData(arr, data, step)"},
index 74d7cde340ade8fcefbf5485f23a20fdd534dc2c..c169d04f87b4684d70ff3394004733f0e8d6d112 100644 (file)
@@ -625,6 +625,12 @@ class FunctionTests(OpenCVTests):
         self.assert_(nd == 3)
         self.assert_((nc * nr * nd) == elems)
 
+        return # XXX - blocked by fixes for #166, #150
+
+        # Now test ReshapeMatND
+        mat = cv.CreateMatND([2, 2, 2], cv.CV_32F)
+        print cv.ReshapeMatND(mat, 0, []);
+
     def test_Save(self):
         for o in [ cv.CreateImage((128,128), cv.IPL_DEPTH_8U, 1), cv.CreateMat(16, 16, cv.CV_32FC1) ]:
             cv.Save("test.save", o)
@@ -743,6 +749,10 @@ class AreaTests(OpenCVTests):
         right_disparity = cv.CreateMat(512, 512, cv.CV_16SC1)
         cv.FindStereoCorrespondenceGC(left, right, left_disparity, right_disparity, gc)
 
+    def test_kalman(self):
+        k = cv.CreateKalman(2, 1, 0)
+        print dir(k)
+
     def failing_test_exception(self):
         a = cv.CreateImage((640, 480), cv.IPL_DEPTH_8U, 1)
         b = cv.CreateImage((640, 480), cv.IPL_DEPTH_8U, 1)