Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
6ebdcb87
Commit
6ebdcb87
authored
May 27, 2010
by
James Bowman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#362, CvMoments fields now exposed, smoke tested by test_moments
parent
1e5f012e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
45 deletions
+118
-45
cv.cpp
modules/python/cv.cpp
+7
-39
gen.py
modules/python/gen.py
+94
-6
test.py
tests/python/test.py
+17
-0
No files found.
modules/python/cv.cpp
View file @
6ebdcb87
...
...
@@ -92,11 +92,6 @@ typedef IplImage ROIplImage;
typedef
const
CvMat
ROCvMat
;
typedef
PyObject
PyCallableObject
;
struct
cvmoments_t
{
PyObject_HEAD
CvMoments
a
;
};
struct
cvfont_t
{
PyObject_HEAD
CvFont
a
;
...
...
@@ -962,21 +957,6 @@ static void memtrack_specials(void)
/************************************************************************/
/* cvmoments */
static
PyTypeObject
cvmoments_Type
=
{
PyObject_HEAD_INIT
(
&
PyType_Type
)
0
,
/*size*/
MODULESTR
".cvmoments"
,
/*name*/
sizeof
(
cvmoments_t
),
/*basicsize*/
};
static
void
cvmoments_specials
(
void
)
{
}
/************************************************************************/
/* cvmemstorage */
static
void
cvmemstorage_dealloc
(
PyObject
*
self
)
...
...
@@ -2058,17 +2038,6 @@ static int convert_to_floatPTRPTR(PyObject *o, float*** dst, const char *name =
return
1
;
}
static
int
convert_to_CvMomentsPTR
(
PyObject
*
o
,
CvMoments
**
dst
,
const
char
*
name
=
"no_name"
)
{
if
(
PyType_IsSubtype
(
o
->
ob_type
,
&
cvmoments_Type
))
{
(
*
dst
)
=
&
(((
cvmoments_t
*
)
o
)
->
a
);
return
1
;
}
else
{
(
*
dst
)
=
(
CvMoments
*
)
NULL
;
return
failmsg
(
"Expected CvMoments for argument '%s'"
,
name
);
}
}
static
int
convert_to_CvFontPTR
(
PyObject
*
o
,
CvFont
**
dst
,
const
char
*
name
=
"no_name"
)
{
if
(
PyType_IsSubtype
(
o
->
ob_type
,
&
cvfont_Type
))
{
...
...
@@ -2547,13 +2516,6 @@ static PyObject *FROM_CvRNG(CvRNG r)
return
(
PyObject
*
)
m
;
}
static
PyObject
*
FROM_CvMoments
(
CvMoments
r
)
{
cvmoments_t
*
m
=
PyObject_NEW
(
cvmoments_t
,
&
cvmoments_Type
);
m
->
a
=
r
;
return
(
PyObject
*
)
m
;
}
static
PyObject
*
FROM_CvContourTreePTR
(
CvContourTree
*
r
)
{
cvcontourtree_t
*
m
=
PyObject_NEW
(
cvcontourtree_t
,
&
cvcontourtree_Type
);
...
...
@@ -3615,6 +3577,13 @@ static PyObject *temp_test(PyObject *self, PyObject *args)
printf("count=%d\n", count);
#endif
#if 0
CvMat *src = cvCreateMat(512, 512, CV_8UC3);
CvMat *dst = cvCreateMat(512, 512, CV_8UC3);
cvPyrMeanShiftFiltering(src, dst, 5, 5);
return FROM_CvMat(src);
#endif
return
PyFloat_FromDouble
(
0.0
);
}
...
...
@@ -3845,7 +3814,6 @@ void initcv()
MKTYPE
(
cvmat
);
MKTYPE
(
cvmatnd
);
MKTYPE
(
cvmemstorage
);
MKTYPE
(
cvmoments
);
MKTYPE
(
cvsubdiv2dedge
);
MKTYPE
(
cvrng
);
MKTYPE
(
cvseq
);
...
...
modules/python/gen.py
View file @
6ebdcb87
...
...
@@ -346,7 +346,68 @@ for l in open("%s/defs" % sys.argv[1]):
# gen_c[3] is the code, gen_c[4] initializers
s
=
Template
(
"""
gensimple
=
Template
(
"""
/*
${cvtype} is the OpenCV C struct
${ourname}_t is the Python object
*/
struct ${ourname}_t {
PyObject_HEAD
${cvtype} v;
};
static PyObject *${ourname}_repr(PyObject *self)
{
${ourname}_t *p = (${ourname}_t*)self;
char str[1000];
sprintf(str, "<${ourname}
%
p>", p);
return PyString_FromString(str);
}
${getset_funcs}
static PyGetSetDef ${ourname}_getseters[] = {
${getset_inits}
{NULL} /* Sentinel */
};
static PyTypeObject ${ourname}_Type = {
PyObject_HEAD_INIT(&PyType_Type)
0, /*size*/
MODULESTR".${ourname}", /*name*/
sizeof(${ourname}_t), /*basicsize*/
};
static void ${ourname}_specials(void)
{
${ourname}_Type.tp_repr = ${ourname}_repr;
${ourname}_Type.tp_getset = ${ourname}_getseters;
}
static PyObject *FROM_${cvtype}(${cvtype} r)
{
${ourname}_t *m = PyObject_NEW(${ourname}_t, &${ourname}_Type);
m->v = r;
return (PyObject*)m;
}
static int convert_to_${cvtype}PTR(PyObject *o, ${cvtype}** dst, const char *name = "no_name")
{
${allownull}
if (PyType_IsSubtype(o->ob_type, &${ourname}_Type)) {
*dst = &(((${ourname}_t*)o)->v);
return 1;
} else {
(*dst) = (${cvtype}*)NULL;
return failmsg("Expected ${cvtype} for argument '
%
s'", name);
}
}
"""
)
genptr
=
Template
(
"""
/*
${cvtype} is the OpenCV C struct
${ourname}_t is the Python object
...
...
@@ -368,7 +429,7 @@ static PyObject *${ourname}_repr(PyObject *self)
{
${ourname}_t *p = (${ourname}_t*)self;
char str[1000];
sprintf(str, "<${ourname}
%
p>", p
->v
);
sprintf(str, "<${ourname}
%
p>", p);
return PyString_FromString(str);
}
...
...
@@ -418,7 +479,7 @@ static int convert_to_${cvtype}PTR(PyObject *o, ${cvtype}** dst, const char *nam
getset_func_template
=
Template
(
"""
static PyObject *${ourname}_get_${member}(${ourname}_t *p, void *closure)
{
return ${rconverter}(p->v
->
${member});
return ${rconverter}(p->v
${accessor}
${member});
}
static int ${ourname}_set_${member}(${ourname}_t *p, PyObject *value, void *closure)
...
...
@@ -433,7 +494,7 @@ static int ${ourname}_set_${member}(${ourname}_t *p, PyObject *value, void *clos
return -1;
}
p->v
->
${member} = ${converter}(value);
p->v
${accessor}
${member} = ${converter}(value);
return 0;
}
...
...
@@ -494,6 +555,26 @@ objects = [
"gain"
:
'mr'
,
"error_cov_post"
:
'mr'
,
}),
(
'CvMoments'
,
[
'copy'
],
{
"m00"
:
'f'
,
"m10"
:
'f'
,
"m01"
:
'f'
,
"m20"
:
'f'
,
"m11"
:
'f'
,
"m02"
:
'f'
,
"m30"
:
'f'
,
"m21"
:
'f'
,
"m12"
:
'f'
,
"m03"
:
'f'
,
"mu20"
:
'f'
,
"mu11"
:
'f'
,
"mu02"
:
'f'
,
"mu30"
:
'f'
,
"mu21"
:
'f'
,
"mu12"
:
'f'
,
"mu03"
:
'f'
,
"inv_sqrt_m00"
:
'f'
,
}),
]
checkers
=
{
...
...
@@ -528,7 +609,11 @@ for (t, flags, members) in objects:
map
=
{
'cvtype'
:
t
,
'ourname'
:
t
.
replace
(
'Cv'
,
''
)}
# gsf is all the generated code for the member accessors
gsf
=
""
.
join
([
getset_func_template
.
substitute
(
map
,
member
=
m
,
checker
=
checkers
[
t
],
converter
=
converters
[
t
],
rconverter
=
rconverters
[
t
],
typename
=
typenames
[
t
])
for
(
m
,
t
)
in
members
.
items
()])
if
'copy'
in
flags
:
a
=
'.'
else
:
a
=
'->'
gsf
=
""
.
join
([
getset_func_template
.
substitute
(
map
,
accessor
=
a
,
member
=
m
,
checker
=
checkers
[
t
],
converter
=
converters
[
t
],
rconverter
=
rconverters
[
t
],
typename
=
typenames
[
t
])
for
(
m
,
t
)
in
members
.
items
()])
# gsi is the generated code for the initializer for each accessor
gsi
=
""
.
join
([
getset_init_template
.
substitute
(
map
,
member
=
m
)
for
(
m
,
t
)
in
members
.
items
()])
# s is the template that pulls everything together
...
...
@@ -536,7 +621,10 @@ for (t, flags, members) in objects:
nullcode
=
"""if (o == Py_None) { *dst = (
%
s*)NULL; return 1; }"""
%
map
[
'cvtype'
]
else
:
nullcode
=
""
print
>>
gen_c
[
3
],
s
.
substitute
(
map
,
getset_funcs
=
gsf
,
getset_inits
=
gsi
,
allownull
=
nullcode
)
if
'copy'
in
flags
:
print
>>
gen_c
[
3
],
gensimple
.
substitute
(
map
,
getset_funcs
=
gsf
,
getset_inits
=
gsi
,
allownull
=
nullcode
)
else
:
print
>>
gen_c
[
3
],
genptr
.
substitute
(
map
,
getset_funcs
=
gsf
,
getset_inits
=
gsi
,
allownull
=
nullcode
)
print
>>
gen_c
[
4
],
"MKTYPE(
%
s);"
%
map
[
'ourname'
]
for
f
in
gen_c
:
...
...
tests/python/test.py
View file @
6ebdcb87
...
...
@@ -698,6 +698,19 @@ class FunctionTests(OpenCVTests):
r
=
cv
.
MinMaxLoc
(
scribble
)
self
.
assert_
(
r
==
(
0
,
255
,
tuple
(
reversed
(
lo
)),
tuple
(
reversed
(
hi
))))
def
xxx_test_PyrMeanShiftFiltering
(
self
):
# XXX - ticket #306
if
0
:
src
=
self
.
get_sample
(
"samples/c/lena.jpg"
,
cv
.
CV_LOAD_IMAGE_COLOR
)
dst
=
cv
.
CloneMat
(
src
)
cv
.
PyrMeanShiftFiltering
(
src
,
dst
,
5
,
5
)
print
src
,
dst
self
.
snap
(
src
)
else
:
r
=
cv
.
temp_test
()
print
r
print
len
(
r
.
tostring
())
self
.
snap
(
r
)
def
test_Reshape
(
self
):
# 97 rows
# 12 cols
...
...
@@ -1774,6 +1787,10 @@ class AreaTests(OpenCVTests):
def
test_moments
(
self
):
im
=
self
.
get_sample
(
"samples/c/lena.jpg"
,
0
)
mo
=
cv
.
Moments
(
im
)
for
fld
in
[
"m00"
,
"m10"
,
"m01"
,
"m20"
,
"m11"
,
"m02"
,
"m30"
,
"m21"
,
"m12"
,
"m03"
,
"mu20"
,
"mu11"
,
"mu02"
,
"mu30"
,
"mu21"
,
"mu12"
,
"mu03"
,
"inv_sqrt_m00"
]:
self
.
assert_
(
isinstance
(
getattr
(
mo
,
fld
),
float
))
print
getattr
(
mo
,
fld
)
orders
=
[]
for
x_order
in
range
(
4
):
for
y_order
in
range
(
4
-
x_order
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment