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
3159bd1a
Commit
3159bd1a
authored
Jul 01, 2011
by
Andrey Pavlenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#863: 'string' args support added
parent
6c8a2b88
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
159 additions
and
128 deletions
+159
-128
gen_java.py
modules/java/gen_java.py
+113
-119
Mat.cpp
modules/java/src/cpp/Mat.cpp
+33
-9
Mat.java
modules/java/src/java/Mat.java
+10
-0
Sample1View.java
...android/1-java/src/org/opencv/samples/s1/Sample1View.java
+3
-0
No files found.
modules/java/gen_java.py
View file @
3159bd1a
...
...
@@ -6,34 +6,56 @@ try:
except
:
from
StringIO
import
StringIO
ctype2j
=
{
# c : (j, jn, jni, jni code)
""
:
(
""
,
"long"
,
"jlong"
,
""
),
# c-tor
"void"
:
(
"void"
,
"void"
,
"void"
,
""
),
"bool"
:
(
"boolean"
,
"boolean"
,
"jboolean"
,
"Z"
),
"int"
:
(
"int"
,
"int"
,
"jint"
,
"I"
),
"long"
:
(
"int"
,
"int"
,
"jint"
,
"I"
),
"float"
:
(
"float"
,
"float"
,
"jfloat"
,
"F"
),
"double"
:
(
"double"
,
"double"
,
"jdouble"
,
"D"
),
"size_t"
:
(
"long"
,
"long"
,
"jlong"
,
"J"
),
"env"
:
(
""
,
""
,
"JNIEnv*"
,
""
),
# dummy 'env'
"cls"
:
(
""
,
""
,
"jclass"
,
""
),
# dummy 'cls'
#
"Mat"
:
(
"Mat"
,
((
"size_t"
,
".nativeObj"
),),
"*
%(n)
s"
,
"J"
),
"Point"
:
(
"Point"
,
((
"double"
,
".x"
),
(
"double"
,
".y"
)),
"cv::Point((int)
%(n)
s_x, (int)
%(n)
s_y)"
,
"DD"
),
"Point2f"
:
(
"Point"
,
((
"double"
,
".x"
),
(
"double"
,
".y"
)),
"cv::Point2f((float)
%(n)
s_x, (float)
%(n)
s_y)"
,
"DD"
),
"Point2d"
:
(
"Point"
,
((
"double"
,
".x"
),
(
"double"
,
".y"
)),
"cv::Point2d(
%(n)
s_x,
%(n)
s_y)"
,
"DD"
),
"Point3i"
:
(
"Point"
,
((
"double"
,
".x"
),
(
"double"
,
".y"
),
(
"double"
,
".z"
)),
\
"cv::Point3i((int)
%(n)
s_x, (int)
%(n)
s_y, (int)
%(n)
s_z)"
,
"DDD"
),
"Point3f"
:
(
"Point"
,
((
"double"
,
".x"
),
(
"double"
,
".y"
),
(
"double"
,
".z"
)),
\
"cv::Point3f((float)
%(n)
s_x, (float)
%(n)
s_y, (float)
%(n)
s_z)"
,
"DDD"
),
"Point3d"
:
(
"Point"
,
((
"double"
,
".x"
),
(
"double"
,
".y"
),
(
"double"
,
".z"
)),
\
"cv::Point3d(
%(n)
s_x,
%(n)
s_y,
%(n)
s_z)"
,
"DDD"
),
"Rect"
:
(
"Rect"
,
((
"int"
,
".x"
),
(
"int"
,
".y"
),
(
"int"
,
".width"
),
(
"int"
,
".height"
)),
\
"cv::Rect(
%(n)
s_x,
%(n)
s_y,
%(n)
s_width,
%(n)
s_height)"
,
"IIII"
),
"Size"
:
(
"Size"
,
((
"int"
,
".width"
),
(
"int"
,
".height"
)),
"cv::Size(
%(n)
s_width,
%(n)
s_height)"
,
"II"
),
"Scalar"
:
(
"Scalar"
,
((
"double"
,
".v0"
),
(
"double"
,
".v1"
),
(
"double"
,
".v2"
),
(
"double"
,
".v3"
)),
\
"cv::Scalar(
%(n)
s_v0,
%(n)
s_v1,
%(n)
s_v2,
%(n)
s_v3)"
,
"DDDD"
),
# c_type : { java/jni correspondence }
type_dict
=
{
# "simple" : { j_type : "?", jn_type : "?", jni_type : "?", suffix : "?" },
""
:
{
"j_type"
:
""
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
},
# c-tor ret_type
"void"
:
{
"j_type"
:
"void"
,
"jn_type"
:
"void"
,
"jni_type"
:
"void"
},
"env"
:
{
"j_type"
:
""
,
"jn_type"
:
""
,
"jni_type"
:
"JNIEnv*"
},
"cls"
:
{
"j_type"
:
""
,
"jn_type"
:
""
,
"jni_type"
:
"jclass"
},
"bool"
:
{
"j_type"
:
"boolean"
,
"jn_type"
:
"boolean"
,
"jni_type"
:
"jboolean"
,
"suffix"
:
"Z"
},
"int"
:
{
"j_type"
:
"int"
,
"jn_type"
:
"int"
,
"jni_type"
:
"int"
,
"suffix"
:
"I"
},
"long"
:
{
"j_type"
:
"int"
,
"jn_type"
:
"int"
,
"jni_type"
:
"int"
,
"suffix"
:
"I"
},
"float"
:
{
"j_type"
:
"float"
,
"jn_type"
:
"float"
,
"jni_type"
:
"jfloat"
,
"suffix"
:
"F"
},
"double"
:
{
"j_type"
:
"double"
,
"jn_type"
:
"double"
,
"jni_type"
:
"jdouble"
,
"suffix"
:
"D"
},
"size_t"
:
{
"j_type"
:
"long"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"suffix"
:
"J"
},
"__int64"
:
{
"j_type"
:
"long"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"suffix"
:
"J"
},
#"+Mat+" : { "j_type" : "Mat", "jn_type" : "long", "jn_name" : "%s.nativeObj", "jni_type" : "jlong", "suffix" : "J" },
# "complex" : { j_type : "?", jn_args : (("", ""),), jn_name : "", jni_var : "", jni_name : "", "suffix" : "?" },
"Mat"
:
{
"j_type"
:
"Mat"
,
"jn_type"
:
"long"
,
"jn_args"
:
((
"__int64"
,
".nativeObj"
),),
"jni_var"
:
"cv::Mat
%(n)
s(
%(n)
s_nativeObj ? *((cv::Mat*)
%(n)
s_nativeObj) : cv::Mat())"
,
"jni_type"
:
"jlong"
,
"suffix"
:
"J"
},
"Point"
:
{
"j_type"
:
"Point"
,
"jn_args"
:
((
"double"
,
".x"
),
(
"double"
,
".y"
)),
"jni_var"
:
"cv::Point
%(n)
s((int)
%(n)
s_x, (int)
%(n)
s_y)"
,
"suffix"
:
"DD"
},
"Point2f"
:
{
"j_type"
:
"Point"
,
"jn_args"
:
((
"double"
,
".x"
),
(
"double"
,
".y"
)),
"jni_var"
:
"cv::Point2f
%(n)
s((float)
%(n)
s_x, (float)
%(n)
s_y)"
,
"suffix"
:
"DD"
},
"Point2d"
:
{
"j_type"
:
"Point"
,
"jn_args"
:
((
"double"
,
".x"
),
(
"double"
,
".y"
)),
"jni_var"
:
"cv::Point2d
%(n)
s(
%(n)
s_x,
%(n)
s_y)"
,
"suffix"
:
"DD"
},
"Point3i"
:
{
"j_type"
:
"Point"
,
"jn_args"
:
((
"double"
,
".x"
),
(
"double"
,
".y"
),
(
"double"
,
".z"
)),
"jni_var"
:
"cv::Point3i
%(n)
s((int)
%(n)
s_x, (int)
%(n)
s_y, (int)
%(n)
s_z)"
,
"suffix"
:
"DDD"
},
"Point3f"
:
{
"j_type"
:
"Point"
,
"jn_args"
:
((
"double"
,
".x"
),
(
"double"
,
".y"
),
(
"double"
,
".z"
)),
"jni_var"
:
"cv::Point3f
%(n)
s((float)
%(n)
s_x, (float)
%(n)
s_y, (float)
%(n)
s_z)"
,
"suffix"
:
"DDD"
},
"Point3d"
:
{
"j_type"
:
"Point"
,
"jn_args"
:
((
"double"
,
".x"
),
(
"double"
,
".y"
),
(
"double"
,
".z"
)),
"jni_var"
:
"cv::Point3d
%(n)
s(
%(n)
s_x,
%(n)
s_y,
%(n)
s_z)"
,
"suffix"
:
"DDD"
},
"Rect"
:
{
"j_type"
:
"Rect"
,
"jn_args"
:
((
"int"
,
".x"
),
(
"int"
,
".y"
),
(
"int"
,
".width"
),
(
"int"
,
".height"
)),
"jni_var"
:
"cv::Rect
%(n)
s(
%(n)
s_x,
%(n)
s_y,
%(n)
s_width,
%(n)
s_height)"
,
"suffix"
:
"IIII"
},
"Size"
:
{
"j_type"
:
"Size"
,
"jn_args"
:
((
"int"
,
".width"
),
(
"int"
,
".height"
)),
"jni_var"
:
"cv::Size
%(n)
s(
%(n)
s_width,
%(n)
s_height)"
,
"suffix"
:
"II"
},
"Scalar"
:
{
"j_type"
:
"Scalar"
,
"jn_args"
:
((
"double"
,
".v0"
),
(
"double"
,
".v1"
),
(
"double"
,
".v2"
),
(
"double"
,
".v3"
)),
"jni_var"
:
"cv::Scalar
%(n)
s(
%(n)
s_v0,
%(n)
s_v1,
%(n)
s_v2,
%(n)
s_v3)"
,
"suffix"
:
"DDDD"
},
"string"
:
{
"j_type"
:
"java.lang.String"
,
"jn_type"
:
"java.lang.String"
,
"jni_type"
:
"jstring"
,
"jni_name"
:
"n_
%(n)
s"
,
"jni_var"
:
'const char* utf_
%(n)
s = env->GetStringUTFChars(
%(n)
s, 0); std::string n_
%(n)
s( utf_
%(n)
s ? utf_
%(n)
s : "" ); env->ReleaseStringUTFChars(
%(n)
s, utf_
%(n)
s);'
,
"suffix"
:
"Ljava_lang_String_2"
},
}
...
...
@@ -95,13 +117,13 @@ class FuncInfo(object):
self
.
static
=
[
""
,
"static"
][
"/S"
in
decl
[
2
]
]
self
.
ctype
=
decl
[
1
]
or
""
self
.
args
=
[]
self
.
jni_suffix
=
"__"
if
self
.
classname
and
self
.
ctype
and
not
self
.
static
:
# non-static class methods except c-tors
self
.
jni_suffix
+=
"J"
# artifical 'self'
#
self.jni_suffix = "__"
#
if self.classname and self.ctype and not self.static: # non-static class methods except c-tors
#
self.jni_suffix += "J" # artifical 'self'
for
a
in
decl
[
3
]:
ai
=
ArgInfo
(
a
)
self
.
args
.
append
(
ai
)
self
.
jni_suffix
+=
ctype2j
.
get
(
ai
.
ctype
,
[
""
,
""
,
""
,
""
])[
3
]
#
self.jni_suffix += ctype2j.get(ai.ctype, ["","","",""])[3]
...
...
@@ -139,10 +161,13 @@ class JavaWrapperGenerator(object):
(
classinfo
.
name
,
classinfo
.
cname
)
sys
.
exit
(
-
1
)
self
.
classes
[
classinfo
.
name
]
=
classinfo
if
classinfo
.
name
in
ctype2j
:
if
classinfo
.
name
in
type_dict
:
print
"Duplicated class: "
+
classinfo
.
name
sys
.
exit
(
-
1
)
ctype2j
[
classinfo
.
name
]
=
(
classinfo
.
jname
,
((
"size_t"
,
".nativeObj"
),),
"*
%(n)
s"
,
"J"
)
type_dict
[
classinfo
.
name
]
=
\
{
"j_type"
:
classinfo
.
name
,
"jn_args"
:
((
"__int64"
,
".nativeObj"
),),
"jni_name"
:
"(*((cv::"
+
classinfo
.
name
+
"*)
%
s_nativeObj))"
,
"suffix"
:
"J"
}
def
add_const
(
self
,
decl
):
# [ "const cname", val, [], [] ]
...
...
@@ -287,87 +312,73 @@ public class %(module)s {
c_decl
=
"
%
s
%
s
%
s(
%
s)"
%
\
(
fi
.
static
,
fi
.
ctype
,
fi
.
cname
,
\
", "
.
join
(
a
.
ctype
+
" "
+
a
.
name
+
[
""
,
" = "
+
a
.
defval
][
bool
(
a
.
defval
)]
for
a
in
fi
.
args
)
)
indent
=
"
"
indent
=
"
"
*
4
if
fi
.
classname
:
indent
=
" "
*
4
self
.
java_code
.
write
(
"
\n
%
s//
%
s
\n
"
%
(
indent
,
c_decl
)
)
indent
+
=
" "
*
4
self
.
java_code
.
write
(
"
\n
%
s//
%
s
\n
"
%
(
indent
,
c_decl
)
)
self
.
cpp_code
.
write
(
"
\n
//
\n
//
%
s
\n
//
\n
"
%
c_decl
)
# check if we 'know' all the types
if
fi
.
ctype
and
fi
.
ctype
!=
"Mat"
and
fi
.
ctype
[
0
]
.
isupper
():
# ret val is class, NYI (TODO!)
self
.
java_code
.
write
(
"
%
s// Return type '
%
s' is not yet supported, skipping the function
\n\n
"
\
%
(
indent
,
fi
.
ctype
)
)
type_info
=
type_dict
.
get
(
fi
.
ctype
)
if
not
(
type_info
and
type_info
.
get
(
"jn_type"
)):
# unsupported ret type
msg
=
"// Return type '
%
s' is not supported, skipping the function
\n\n
"
%
fi
.
ctype
self
.
java_code
.
write
(
indent
+
msg
)
self
.
cpp_code
.
write
(
msg
)
print
"SKIP:"
,
c_decl
,
"
\n\t
due to RET type"
,
fi
.
ctype
return
types
=
[
fi
.
ctype
]
types
.
extend
([
a
.
ctype
for
a
in
fi
.
args
])
for
t
in
types
:
if
t
not
in
ctype2j
:
self
.
java_code
.
write
(
"
%
s// Unknown type '
%
s', skipping the function
\n\n
"
%
(
indent
,
t
)
)
print
"SKIP:"
,
c_decl
,
"
\n\t
due to ARG type"
,
t
return
for
a
in
fi
.
args
:
if
a
.
ctype
[
0
]
.
isupper
()
and
a
.
ctype
!=
"Mat"
and
a
.
out
:
# C++ reference to a class (gcc disallows temp obj reference)
self
.
java_code
.
write
(
"
%
s// Unknown type '
%
s&', skipping the function
\n\n
"
%
(
indent
,
t
)
)
print
"SKIP:"
,
c_decl
,
"
\n\t
due to ARG type"
,
a
.
ctype
+
"&"
if
a
.
ctype
not
in
type_dict
:
msg
=
"// Unknown type '
%
s', skipping the function
\n\n
"
%
a
.
ctype
self
.
java_code
.
write
(
indent
+
msg
)
self
.
cpp_code
.
write
(
msg
)
print
"SKIP:"
,
c_decl
,
"
\n\t
due to ARG type"
,
a
.
ctype
return
if
fi
.
cname
==
"minEnclosingCircle"
:
self
.
java_code
.
write
(
"
%
s// Temporary skipping the function
%
s
\n\n
"
%
(
indent
,
fi
.
cname
)
)
print
"SKIP:"
,
c_decl
,
"
\n\t
due to Temporary filtering"
if
a
.
ctype
!=
"Mat"
and
"jn_args"
in
type_dict
[
a
.
ctype
]
and
a
.
out
:
# complex out args not yet supported
msg
=
"// Unsupported type '
%
s&', skipping the function
\n\n
"
%
a
.
ctype
self
.
java_code
.
write
(
indent
+
msg
)
self
.
cpp_code
.
write
(
msg
)
print
"SKIP:"
,
c_decl
,
"
\n\t
due to OUT ARG of type"
,
a
.
ctype
return
self
.
ported_func_counter
+=
1
# java args
args
=
fi
.
args
[:]
args
=
fi
.
args
[:]
# copy
if
args
and
args
[
-
1
]
.
defval
:
isoverload
=
True
suffix
=
fi
.
jni_suffix
while
True
:
# java native method args
# java native method args
jn_args
=
[]
if
fi
.
classname
and
fi
.
ctype
and
not
fi
.
static
:
# non-static class method except c-tor
jn_args
.
append
(
ArgInfo
([
"size_t"
,
"nativeObj"
,
""
,
[],
""
]))
# adding 'this'
for
a
in
args
:
if
a
.
ctype
[
0
]
.
isupper
():
# Point/Rect/...
#"Point" : ("Point", [["int", ".x"], ["int", ".y"]], ...)
fields
=
ctype2j
[
a
.
ctype
][
1
]
for
f
in
fields
:
jn_args
.
append
(
ArgInfo
([
f
[
0
],
a
.
name
+
f
[
1
],
""
,
[],
""
])
)
else
:
jn_args
.
append
(
a
)
# jni (cpp) function args
jni_args
=
[
ArgInfo
([
"env"
,
"env"
,
""
,
[],
""
]),
ArgInfo
([
"cls"
,
"cls"
,
""
,
[],
""
])]
if
fi
.
classname
and
fi
.
ctype
and
not
fi
.
static
:
jni_args
.
append
(
ArgInfo
([
"size_t"
,
"self"
,
""
,
[],
""
]))
suffix
=
"__"
if
fi
.
classname
and
fi
.
ctype
and
not
fi
.
static
:
# non-static class method except c-tor
# adding 'self'
jn_args
.
append
(
ArgInfo
([
"__int64"
,
"nativeObj"
,
""
,
[],
""
])
)
jni_args
.
append
(
ArgInfo
([
"__int64"
,
"self"
,
""
,
[],
""
])
)
suffix
+=
"J"
for
a
in
args
:
if
a
.
ctype
[
0
]
.
isupper
():
# Point/Rect/...
#"Point" : ("Point", [["int", ".x"], ["int", ".y"]], ...)
fields
=
ctype2j
[
a
.
ctype
][
1
]
suffix
+=
type_dict
[
a
.
ctype
]
.
get
(
"suffix"
)
or
""
fields
=
type_dict
[
a
.
ctype
]
.
get
(
"jn_args"
)
or
[]
if
fields
:
# complex type
for
f
in
fields
:
jn_args
.
append
(
ArgInfo
([
f
[
0
],
a
.
name
+
f
[
1
],
""
,
[],
""
])
)
jni_args
.
append
(
ArgInfo
([
f
[
0
],
a
.
name
+
f
[
1
]
.
replace
(
"."
,
"_"
),
""
,
[],
""
])
)
else
:
jn_args
.
append
(
a
)
jni_args
.
append
(
a
)
# java part:
# private java NATIVE method decl
# e.g.
# private static native void n_add(long src1, long src2, long dst, long mask, int dtype);
jn_type
=
""
if
fi
.
ctype
==
"Mat"
:
jn_type
=
"long"
elif
fi
.
ctype
[
0
]
.
isupper
():
jn_type
=
"NYI"
# TODO: NYI
else
:
jn_type
=
ctype2j
[
fi
.
ctype
][
1
]
self
.
java_code
.
write
(
Template
(
\
"
${indent}private static native $jn_type $jn_name($jn_args);
\n
"
)
.
substitute
(
\
"${indent}private static native $jn_type $jn_name($jn_args);
\n
"
)
.
substitute
(
\
indent
=
indent
,
\
jn_type
=
jn_type
,
\
jn_name
=
fi
.
jn_name
,
\
jn_args
=
", "
.
join
([
"
%
s
%
s"
%
(
ctype2j
[
a
.
ctype
][
1
],
a
.
name
.
replace
(
"."
,
"_"
))
for
a
in
jn_args
])
jn_type
=
type_dict
[
fi
.
ctype
][
"jn_type"
]
,
\
jn_name
=
fi
.
jn_name
,
\
jn_args
=
", "
.
join
([
"
%
s
%
s"
%
(
type_dict
[
a
.
ctype
][
"jn_type"
],
a
.
name
.
replace
(
"."
,
"_"
))
for
a
in
jn_args
])
)
);
# java part:
...
...
@@ -375,11 +386,11 @@ public class %(module)s {
# e.g.
# public static void add( Mat src1, Mat src2, Mat dst, Mat mask, int dtype )
# { n_add( src1.nativeObj, src2.nativeObj, dst.nativeObj, mask.nativeObj, dtype ); }
impl_code
=
"
return $jn_name($jn_args_call);
"
impl_code
=
"
return $jn_name($jn_args_call);
"
if
fi
.
ctype
==
"void"
:
impl_code
=
"
$jn_name($jn_args_call);
"
impl_code
=
"
$jn_name($jn_args_call);
"
elif
fi
.
ctype
==
""
:
# c-tor
impl_code
=
"
nativeObj = $jn_name($jn_args_call);
"
impl_code
=
"
nativeObj = $jn_name($jn_args_call);
"
elif
fi
.
ctype
in
self
.
classes
:
# wrapped class
impl_code
=
" return new
%
s( $jn_name($jn_args_call) ); "
%
\
self
.
classes
[
fi
.
ctype
]
.
jname
...
...
@@ -389,18 +400,18 @@ public class %(module)s {
static
=
fi
.
static
self
.
java_code
.
write
(
Template
(
\
"
${indent}public $static $j_type $j_name($j_args)"
)
.
substitute
(
\
"${indent}public $static $j_type $j_name($j_args)"
)
.
substitute
(
\
indent
=
indent
,
\
static
=
static
,
\
j_type
=
ctype2j
[
fi
.
ctype
][
0
],
\
j_type
=
type_dict
[
fi
.
ctype
][
"j_type"
],
\
j_name
=
fi
.
jname
,
\
j_args
=
", "
.
join
([
"
%
s
%
s"
%
(
ctype2j
[
a
.
ctype
][
0
],
a
.
name
)
for
a
in
args
])
\
j_args
=
", "
.
join
([
"
%
s
%
s"
%
(
type_dict
[
a
.
ctype
][
"j_type"
],
a
.
name
)
for
a
in
args
])
\
)
)
self
.
java_code
.
write
(
Template
(
"
\n
$indent{ "
+
impl_code
+
" }
\n
"
)
.
substitute
(
\
self
.
java_code
.
write
(
Template
(
"
\n
$indent{ "
+
impl_code
+
" }
\n
"
)
.
substitute
(
\
indent
=
indent
,
\
jn_name
=
fi
.
jn_name
,
\
jn_args_call
=
", "
.
join
(
[
a
.
name
+
[
""
,
".nativeObj"
][
ctype2j
[
a
.
ctype
][
0
]
==
"Mat"
]
for
a
in
jn_args
]
)
\
jn_args_call
=
", "
.
join
(
[
a
.
name
for
a
in
jn_args
]
)
\
)
)
# cpp part:
...
...
@@ -408,10 +419,8 @@ public class %(module)s {
ret
=
"return "
if
fi
.
ctype
==
"void"
:
ret
=
""
elif
fi
.
ctype
==
"Mat"
:
ret
=
"return (jlong) new cv::Mat"
elif
fi
.
ctype
[
0
]
.
isupper
():
ret
=
NYI
# NYI
elif
fi
.
ctype
in
self
.
classes
:
# wrapped class:
ret
=
"return (jlong) new cv::"
+
self
.
classes
[
fi
.
ctype
]
.
jname
cvname
=
"cv::"
+
fi
.
name
j2cvargs
=
[]
...
...
@@ -421,32 +430,18 @@ public class %(module)s {
elif
fi
.
static
:
cvname
=
"cv::
%
s::
%
s"
%
(
fi
.
classname
,
fi
.
name
)
else
:
cvname
=
"
%
s->
%
s"
%
(
"me"
,
fi
.
name
)
cvname
=
"
me->"
+
fi
.
name
j2cvargs
.
append
(
\
"cv::
%
s* me = (cv::
%
s*) self; //TODO: check for NULL"
%
\
(
fi
.
classname
,
fi
.
classname
)
\
"cv::
%
(cls)
s* me = (cv::
%(cls)
s*) self; //TODO: check for NULL"
\
%
{
"cls"
:
fi
.
classname
}
\
)
cvargs
=
[]
for
a
in
args
:
cva
=
a
.
name
if
a
.
ctype
[
0
]
.
isupper
():
# Point/Rect/...
# "Point" : ("Point", (("int", ".x"), ("int", ".y")), "Point(%(n)s_x, %(n)s_y)", "II")
# Point(p_x, p_y)
cva
=
ctype2j
[
a
.
ctype
][
2
]
%
{
"n"
:
a
.
name
}
if
a
.
ctype
==
"Mat"
:
j2cvargs
.
append
(
"cv::Mat*
%
s = (cv::Mat*)
%
s_nativeObj; //TODO: check for NULL"
\
%
(
a
.
name
,
a
.
name
))
pass
cvargs
.
append
(
cva
)
rtype
=
"NYI"
if
fi
.
ctype
==
"Mat"
:
rtype
=
"jlong"
elif
fi
.
ctype
[
0
]
.
isupper
():
rtype
=
"NYI"
# TODO: NYI
else
:
rtype
=
ctype2j
[
fi
.
ctype
][
2
]
cvargs
.
append
(
type_dict
[
a
.
ctype
]
.
get
(
"jni_name"
,
"
%(n)
s"
)
%
{
"n"
:
a
.
name
})
if
"jni_var"
in
type_dict
[
a
.
ctype
]:
# complex type
j2cvargs
.
append
(
type_dict
[
a
.
ctype
][
"jni_var"
]
%
{
"n"
:
a
.
name
}
+
";"
)
rtype
=
type_dict
[
fi
.
ctype
][
"jni_type"
]
self
.
cpp_code
.
write
(
Template
(
\
"""
#ifdef __cplusplus
...
...
@@ -471,7 +466,7 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname
rtype
=
rtype
,
\
module
=
self
.
module
,
\
fname
=
fi
.
jni_name
+
[
""
,
suffix
][
isoverload
],
\
args
=
", "
.
join
([
"
%
s
%
s"
%
(
ctype2j
[
a
.
ctype
][
2
]
,
a
.
name
)
for
a
in
jni_args
]),
\
args
=
", "
.
join
([
"
%
s
%
s"
%
(
type_dict
[
a
.
ctype
]
.
get
(
"jni_type"
)
,
a
.
name
)
for
a
in
jni_args
]),
\
j2cv
=
"
\n
"
.
join
([
a
for
a
in
j2cvargs
]),
\
ret
=
ret
,
\
cvname
=
cvname
,
\
...
...
@@ -481,7 +476,6 @@ JNIEXPORT $rtype JNICALL Java_org_opencv_${module}_$fname
# processing args with default values
if
args
and
args
[
-
1
]
.
defval
:
a
=
args
.
pop
()
suffix
=
suffix
[
0
:
-
len
(
ctype2j
[
a
.
ctype
][
3
])]
else
:
break
...
...
modules/java/src/cpp/Mat.cpp
View file @
3159bd1a
...
...
@@ -292,7 +292,7 @@ JNIEXPORT jlong JNICALL Java_org_opencv_Mat_nClone
}
// unlike other nPut()-s this one (with double[]) should convert input values to correct type
#define PUT_ITEM(T, R, C) for(int ch=0; ch<me->channels() & count>0; ch++,count--) *((T*)me->ptr(R, C)+ch) = cv::saturate_cast<T>(*(src+ch))
#define PUT_ITEM(T, R, C) for(int ch=0; ch<me->channels() &
&
count>0; ch++,count--) *((T*)me->ptr(R, C)+ch) = cv::saturate_cast<T>(*(src+ch))
JNIEXPORT
jint
JNICALL
Java_org_opencv_Mat_nPutD
(
JNIEnv
*
env
,
jclass
cls
,
jlong
self
,
jint
row
,
jint
col
,
jint
count
,
jdoubleArray
vals
)
{
...
...
@@ -306,7 +306,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD
double
*
values
=
(
double
*
)
env
->
GetPrimitiveArrayCritical
(
vals
,
0
);
double
*
src
=
values
;
int
r
,
c
;
for
(
c
=
col
;
c
<
me
->
cols
&
count
>
0
;
c
++
)
for
(
c
=
col
;
c
<
me
->
cols
&
&
count
>
0
;
c
++
)
{
switch
(
me
->
depth
())
{
case
CV_8U
:
PUT_ITEM
(
uchar
,
row
,
c
);
break
;
...
...
@@ -320,8 +320,8 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nPutD
src
++
;
}
for
(
r
=
row
+
1
;
r
<
me
->
rows
&
count
>
0
;
r
++
)
for
(
c
=
0
;
c
<
me
->
cols
&
count
>
0
;
c
++
)
for
(
r
=
row
+
1
;
r
<
me
->
rows
&
&
count
>
0
;
r
++
)
for
(
c
=
0
;
c
<
me
->
cols
&
&
count
>
0
;
c
++
)
{
switch
(
me
->
depth
())
{
case
CV_8U
:
PUT_ITEM
(
uchar
,
r
,
c
);
break
;
...
...
@@ -475,7 +475,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetS
{
cv
::
Mat
*
me
=
(
cv
::
Mat
*
)
self
;
if
(
!
self
)
return
0
;
// no native object behind
if
(
me
->
depth
()
!=
CV_
8U
&&
me
->
depth
()
!=
CV_8
S
)
return
0
;
// incompatible type
if
(
me
->
depth
()
!=
CV_
16U
&&
me
->
depth
()
!=
CV_16
S
)
return
0
;
// incompatible type
if
(
me
->
rows
<=
row
||
me
->
cols
<=
col
)
return
0
;
// indexes out of range
char
*
values
=
(
char
*
)
env
->
GetPrimitiveArrayCritical
(
vals
,
0
);
...
...
@@ -489,7 +489,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetI
{
cv
::
Mat
*
me
=
(
cv
::
Mat
*
)
self
;
if
(
!
self
)
return
0
;
// no native object behind
if
(
me
->
depth
()
!=
CV_
8U
&&
me
->
depth
()
!=
CV_8
S
)
return
0
;
// incompatible type
if
(
me
->
depth
()
!=
CV_
32
S
)
return
0
;
// incompatible type
if
(
me
->
rows
<=
row
||
me
->
cols
<=
col
)
return
0
;
// indexes out of range
char
*
values
=
(
char
*
)
env
->
GetPrimitiveArrayCritical
(
vals
,
0
);
...
...
@@ -503,7 +503,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetF
{
cv
::
Mat
*
me
=
(
cv
::
Mat
*
)
self
;
if
(
!
self
)
return
0
;
// no native object behind
if
(
me
->
depth
()
!=
CV_
8U
&&
me
->
depth
()
!=
CV_8S
)
return
0
;
// incompatible type
if
(
me
->
depth
()
!=
CV_
32F
)
return
0
;
// incompatible type
if
(
me
->
rows
<=
row
||
me
->
cols
<=
col
)
return
0
;
// indexes out of range
char
*
values
=
(
char
*
)
env
->
GetPrimitiveArrayCritical
(
vals
,
0
);
...
...
@@ -517,7 +517,7 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetD
{
cv
::
Mat
*
me
=
(
cv
::
Mat
*
)
self
;
if
(
!
self
)
return
0
;
// no native object behind
if
(
me
->
depth
()
!=
CV_
8U
&&
me
->
depth
()
!=
CV_8S
)
return
0
;
// incompatible type
if
(
me
->
depth
()
!=
CV_
64F
)
return
0
;
// incompatible type
if
(
me
->
rows
<=
row
||
me
->
cols
<=
col
)
return
0
;
// indexes out of range
char
*
values
=
(
char
*
)
env
->
GetPrimitiveArrayCritical
(
vals
,
0
);
...
...
@@ -526,12 +526,36 @@ JNIEXPORT jint JNICALL Java_org_opencv_Mat_nGetD
return
res
;
}
JNIEXPORT
jdoubleArray
JNICALL
Java_org_opencv_Mat_nGet
(
JNIEnv
*
env
,
jclass
cls
,
jlong
self
,
jint
row
,
jint
col
,
jint
count
)
{
cv
::
Mat
*
me
=
(
cv
::
Mat
*
)
self
;
if
(
!
self
)
return
0
;
// no native object behind
if
(
me
->
rows
<=
row
||
me
->
cols
<=
col
)
return
0
;
// indexes out of range
jdoubleArray
res
=
env
->
NewDoubleArray
(
me
->
channels
());
if
(
res
){
jdouble
buff
[
me
->
channels
()];
int
i
;
switch
(
me
->
depth
()){
case
CV_8U
:
for
(
i
=
0
;
i
<
me
->
channels
();
i
++
)
buff
[
i
]
=
*
((
unsigned
char
*
)
me
->
ptr
(
row
,
col
)
+
i
);
break
;
case
CV_8S
:
for
(
i
=
0
;
i
<
me
->
channels
();
i
++
)
buff
[
i
]
=
*
((
signed
char
*
)
me
->
ptr
(
row
,
col
)
+
i
);
break
;
case
CV_16U
:
for
(
i
=
0
;
i
<
me
->
channels
();
i
++
)
buff
[
i
]
=
*
((
unsigned
short
*
)
me
->
ptr
(
row
,
col
)
+
i
);
break
;
case
CV_16S
:
for
(
i
=
0
;
i
<
me
->
channels
();
i
++
)
buff
[
i
]
=
*
((
signed
short
*
)
me
->
ptr
(
row
,
col
)
+
i
);
break
;
case
CV_32S
:
for
(
i
=
0
;
i
<
me
->
channels
();
i
++
)
buff
[
i
]
=
*
((
int
*
)
me
->
ptr
(
row
,
col
)
+
i
);
break
;
case
CV_32F
:
for
(
i
=
0
;
i
<
me
->
channels
();
i
++
)
buff
[
i
]
=
*
((
float
*
)
me
->
ptr
(
row
,
col
)
+
i
);
break
;
case
CV_64F
:
for
(
i
=
0
;
i
<
me
->
channels
();
i
++
)
buff
[
i
]
=
*
((
double
*
)
me
->
ptr
(
row
,
col
)
+
i
);
break
;
}
env
->
SetDoubleArrayRegion
(
res
,
0
,
me
->
channels
(),
buff
);
}
return
res
;
}
JNIEXPORT
void
JNICALL
Java_org_opencv_Mat_nSetTo
(
JNIEnv
*
env
,
jclass
cls
,
jlong
self
,
jdouble
v0
,
jdouble
v1
,
jdouble
v2
,
jdouble
v3
)
{
cv
::
Mat
*
me
=
(
cv
::
Mat
*
)
self
;
//TODO: check for NULL
me
->
setTo
(
cv
::
Scalar
(
v0
,
v1
,
v2
,
v3
)
,
cv
::
Mat
()
);
me
->
setTo
(
cv
::
Scalar
(
v0
,
v1
,
v2
,
v3
)
);
}
JNIEXPORT
void
JNICALL
Java_org_opencv_Mat_nCopyTo
...
...
modules/java/src/java/Mat.java
View file @
3159bd1a
...
...
@@ -339,6 +339,15 @@ public class Mat {
throw
new
java
.
lang
.
UnsupportedOperationException
(
"Mat data type is not compatible: "
+
t
);
}
public
double
[]
get
(
int
row
,
int
col
)
{
checkNull
();
//CvType t = type();
//if(t.depth() == CvType.CV_64F) {
return
nGet
(
nativeObj
,
row
,
col
);
//}
//throw new java.lang.UnsupportedOperationException("Mat data type is not compatible: " + t);
}
public
void
setTo
(
double
v0
,
double
v1
,
double
v2
,
double
v3
)
{
checkNull
();
...
...
@@ -399,6 +408,7 @@ public class Mat {
private
static
native
int
nGetI
(
long
self
,
int
row
,
int
col
,
int
count
,
int
[]
vals
);
private
static
native
int
nGetF
(
long
self
,
int
row
,
int
col
,
int
count
,
float
[]
vals
);
private
static
native
int
nGetD
(
long
self
,
int
row
,
int
col
,
int
count
,
double
[]
vals
);
private
static
native
double
[]
nGet
(
long
self
,
int
row
,
int
col
);
private
static
native
void
nSetTo
(
long
self
,
double
v0
,
double
v1
,
double
v2
,
double
v3
);
private
static
native
void
nCopyTo
(
long
self
,
long
mat
);
private
static
native
double
nDot
(
long
self
,
long
mat
);
...
...
samples/android/1-java/src/org/opencv/samples/s1/Sample1View.java
View file @
3159bd1a
...
...
@@ -10,6 +10,8 @@ import android.view.SurfaceHolder;
import
android.view.SurfaceView
;
import
org.opencv.Mat
;
import
org.opencv.Point
;
import
org.opencv.Scalar
;
import
org.opencv.Size
;
import
org.opencv.core
;
import
org.opencv.imgproc
;
...
...
@@ -142,6 +144,7 @@ class Sample1View extends SurfaceView implements SurfaceHolder.Callback, Runnabl
break
;
case
Sample1Java
.
VIEW_MODE_RGBA
:
imgproc
.
cvtColor
(
mYuv
,
mRgba
,
imgproc
.
CV_YUV420i2RGB
,
4
);
core
.
putText
(
mRgba
,
"OpenCV + Android"
,
new
Point
(
10
,
100
),
3
/*CV_FONT_HERSHEY_COMPLEX*/
,
2
,
new
Scalar
(
0
,
255
,
0
,
255
),
3
);
break
;
case
Sample1Java
.
VIEW_MODE_CANNY
:
imgproc
.
Canny
(
mGraySubmat
,
mIntermediateMat
,
80
,
100
);
...
...
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