mirror of
https://github.com/opencv/opencv.git
synced 2025-06-11 03:33:28 +08:00
adjust the header parser to support "public virtual" construction and make a tweak for multiple inheritance, fix potential memory problem with Python's IplImage.tostring() method (ticket #1486)
This commit is contained in:
parent
c86c6a028c
commit
d1b5f43700
@ -238,47 +238,18 @@ static PyObject *iplimage_repr(PyObject *self)
|
|||||||
|
|
||||||
static PyObject *iplimage_tostring(PyObject *self, PyObject *args)
|
static PyObject *iplimage_tostring(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
iplimage_t *pc = (iplimage_t*)self;
|
IplImage *i=0;
|
||||||
IplImage *i;
|
|
||||||
if (!convert_to_IplImage(self, &i, "self"))
|
if (!convert_to_IplImage(self, &i, "self"))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (i == NULL)
|
if (i == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
int bps;
|
cv::Mat img(i);
|
||||||
switch (i->depth) {
|
size_t esz = img.elemSize();
|
||||||
case IPL_DEPTH_8U:
|
int nrows = img.rows, ncols = img.cols;
|
||||||
case IPL_DEPTH_8S:
|
|
||||||
bps = 1;
|
if( !img.isContinuous() )
|
||||||
break;
|
img = img.clone();
|
||||||
case IPL_DEPTH_16U:
|
return PyString_FromStringAndSize((char*)img.data, (Py_ssize_t)(esz*nrows*ncols));
|
||||||
case IPL_DEPTH_16S:
|
|
||||||
bps = 2;
|
|
||||||
break;
|
|
||||||
case IPL_DEPTH_32S:
|
|
||||||
case IPL_DEPTH_32F:
|
|
||||||
bps = 4;
|
|
||||||
break;
|
|
||||||
case IPL_DEPTH_64F:
|
|
||||||
bps = 8;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return failmsg("Unrecognised depth %d", i->depth), (PyObject*)0;
|
|
||||||
}
|
|
||||||
int bpl = i->width * i->nChannels * bps;
|
|
||||||
if (PyString_Check(pc->data) && bpl == i->widthStep && pc->offset == 0 && ((bpl * i->height) == what_size(pc->data))) {
|
|
||||||
Py_INCREF(pc->data);
|
|
||||||
return pc->data;
|
|
||||||
} else {
|
|
||||||
int l = bpl * i->height;
|
|
||||||
char *s = new char[l];
|
|
||||||
int y;
|
|
||||||
for (y = 0; y < i->height; y++) {
|
|
||||||
memcpy(s + y * bpl, i->imageData + y * i->widthStep, bpl);
|
|
||||||
}
|
|
||||||
PyObject *r = PyString_FromStringAndSize(s, l);
|
|
||||||
delete[] s;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct PyMethodDef iplimage_methods[] =
|
static struct PyMethodDef iplimage_methods[] =
|
||||||
|
@ -215,9 +215,11 @@ class ClassInfo(object):
|
|||||||
if decl:
|
if decl:
|
||||||
self.bases = decl[1].split()[1:]
|
self.bases = decl[1].split()[1:]
|
||||||
if len(self.bases) > 1:
|
if len(self.bases) > 1:
|
||||||
print "Error: class %s has more than 1 base class (not supported by Python C extensions)" % (self.name,)
|
print "Warning: class %s has more than 1 base class (not supported by Python C extensions)" % (self.name,)
|
||||||
print "Bases: ", self.bases
|
print "Bases: ", self.bases
|
||||||
return sys.exit(-1)
|
print "Only the first base class will be used"
|
||||||
|
self.bases = self.bases[:1]
|
||||||
|
#return sys.exit(-1)
|
||||||
for m in decl[2]:
|
for m in decl[2]:
|
||||||
if m.startswith("="):
|
if m.startswith("="):
|
||||||
self.wname = m[1:]
|
self.wname = m[1:]
|
||||||
|
@ -235,7 +235,7 @@ class CppHeaderParser(object):
|
|||||||
modlist.append("=" + macro_arg)
|
modlist.append("=" + macro_arg)
|
||||||
l = l[:npos] + l[npos3+1:]
|
l = l[:npos] + l[npos3+1:]
|
||||||
|
|
||||||
l = self.batch_replace(l, [("CV_EXPORTS_W", ""), ("CV_EXPORTS", ""), ("public ", " "), ("::", ".")]).strip()
|
l = self.batch_replace(l, [("CV_EXPORTS_W", ""), ("CV_EXPORTS", ""), ("public virtual ", " "), ("public ", " "), ("::", ".")]).strip()
|
||||||
ll = re.split(r'\s*[,:]?\s*', l)
|
ll = re.split(r'\s*[,:]?\s*', l)
|
||||||
ll = [le for le in ll if le]
|
ll = [le for le in ll if le]
|
||||||
classname = ll[1]
|
classname = ll[1]
|
||||||
|
Loading…
Reference in New Issue
Block a user