]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
CvSubRect etc fix for type bug, tostring bug
authorjamesbowman <jamesbowman@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Mon, 5 Oct 2009 23:43:30 +0000 (23:43 +0000)
committerjamesbowman <jamesbowman@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Mon, 5 Oct 2009 23:43:30 +0000 (23:43 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@2225 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/CMakeLists.txt
opencv/interfaces/python/api
opencv/interfaces/python/cv.cpp
opencv/tests/python/tickets.py

index 1d88eb947f535cc7bc6467c1d76a6af26b77a1be..6e539332a7f9e1abc86f0722cb493534c4b7dc83 100644 (file)
@@ -40,6 +40,10 @@ if(MSVC)
     set(CMAKE_USE_RELATIVE_PATHS ON CACHE INTERNAL "" FORCE)\r
 endif()\r
 \r
+#set(CMAKE_C_COMPILER "/opt/BullseyeCoverage/bin/gcc")\r
+#set(CMAKE_CXX_COMPILER "/opt/BullseyeCoverage/bin/g++")\r
+#set(CMAKE_CXX_COMPILER_INIT "/opt/BullseyeCoverage/bin/gcc")\r
+\r
 # --------------------------------------------------------------\r
 # Indicate CMake 2.7 and above that we don't want to mix relative\r
 #  and absolute paths in linker lib lists.\r
index 38409eb4cde12627344f4ddb3ae0007e2d1ec2ac..e3e8746cc180907f5a10d30a0a235c7830902e07 100644 (file)
@@ -258,7 +258,7 @@ Load generic
   char* name NULL
 
 # Accessing Elements and sub-Arrays
-GetRow
+GetRow submat
   CvArr arr
   CvMat submat /J:arr,O,A
   int row
@@ -267,7 +267,7 @@ GetRows submat
   CvMat submat /J:arr,O,A
   int start_row
   int end_row
-  int delta_row -1
+  int delta_row 1
 GetCol submat
   CvArr arr
   CvMat submat /J:arr,O,A
index bc2658286fa2f00fdcf37826e3e8f75f40608e10..37e5c82e09849cf3c8edb4eed6ee077d4b7a0541 100644 (file)
@@ -194,6 +194,24 @@ static PyObject *PyObject_FromCvScalar(CvScalar s, int type)
 static PyObject *cvarr_GetItem(PyObject *o, PyObject *key);
 static int cvarr_SetItem(PyObject *o, PyObject *key, PyObject *v);
 
+// o is a Python string or buffer object.  Return its size.
+
+static Py_ssize_t what_size(PyObject *o)
+{
+  void *buffer;
+  Py_ssize_t buffer_len;
+
+  if (PyString_Check(o)) {
+    return PyString_Size(o);
+  } else if (PyObject_AsWriteBuffer(o, &buffer, &buffer_len) == 0) {
+    return buffer_len;
+  } else {
+    assert(0);  // argument must be string or buffer.
+    return 0;
+  }
+}
+
+
 /************************************************************************/
 
 /* iplimage */
@@ -254,7 +272,7 @@ static PyObject *iplimage_tostring(PyObject *self, PyObject *args)
     return (PyObject*)failmsg("Unrecognised depth %d", i->depth);
   }
   int bpl = i->width * i->nChannels * bps;
-  if (bpl == i->widthStep && pc->offset == 0) {
+  if (bpl == i->widthStep && pc->offset == 0 && ((bpl * i->height) == what_size(pc->data))) {
     Py_INCREF(pc->data);
     return pc->data;
   } else {
@@ -395,9 +413,9 @@ static PyObject *cvmat_tostring(PyObject *self, PyObject *args)
     return (PyObject*)failmsg("Unrecognised depth %d", CV_MAT_DEPTH(m->type));
   }
 
-  int bpl = m->cols * 1 * bps; // bytes per line
+  int bpl = m->cols * bps; // bytes per line
   cvmat_t *pc = (cvmat_t*)self;
-  if (bpl == m->step && pc->offset == 0) {
+  if (bpl == m->step && pc->offset == 0 && ((bpl * m->rows) == what_size(pc->data))) {
     Py_INCREF(pc->data);
     return pc->data;
   } else {
@@ -2626,7 +2644,7 @@ static PyObject *cvarr_GetItem(PyObject *o, PyObject *key)
 
     if (is_cvmat(o) || is_iplimage(o)) {
       cvmat_t *sub = PyObject_NEW(cvmat_t, &cvmat_Type);
-      sub->a = cvCreateMatHeader(dd.length[0], dd.length[1], CV_MAT_CN(cvGetElemType(cva)));
+      sub->a = cvCreateMatHeader(dd.length[0], dd.length[1], cvGetElemType(cva));
       uchar *old0;  // pointer to first element in old mat
       int oldstep;
       cvGetRawData(cva, &old0, &oldstep);
@@ -2640,7 +2658,7 @@ static PyObject *cvarr_GetItem(PyObject *o, PyObject *key)
       return (PyObject*)sub;
     } else {
       cvmatnd_t *sub = PyObject_NEW(cvmatnd_t, &cvmatnd_Type);
-      sub->a = cvCreateMatNDHeader(dd.count, dd.length, CV_MAT_CN(cvGetElemType(cva)));
+      sub->a = cvCreateMatNDHeader(dd.count, dd.length, cvGetElemType(cva));
       uchar *old0;  // pointer to first element in old mat
       cvGetRawData(cva, &old0);
       uchar *new0;  // pointer to first element in new mat
index 15859d5e28b5f647c2b12d73b4ab026fee33be80..a6f33396c8715c48af29dd7fa3a33af27ba2fd31 100644 (file)
@@ -64,6 +64,9 @@ class TestTickets(unittest.TestCase):
         cv.Rectangle(mask, (10,10), (300,100), 255, -1)
         cv.Copy(lena, dst, mask)
         self.snapL([lena, dst, mask])
+        m = cv.CreateMat(480, 640, cv.CV_8UC1)
+        print "ji", m
+        print m.rows, m.cols, m.type, m.step
 
     def snap(self, img):
         self.snapL([img])