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
510ca536
Commit
510ca536
authored
Jul 14, 2011
by
Leonid Beynenson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the function minMaxLoc to JavaAPI as a manual ported function.
Added test for the function.
parent
ab1ff12a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
116 additions
and
0 deletions
+116
-0
coreTest.java
.../java/android_test/src/org/opencv/test/core/coreTest.java
+15
-0
gen_java.py
modules/java/gen_java.py
+101
-0
No files found.
modules/java/android_test/src/org/opencv/test/core/coreTest.java
View file @
510ca536
...
@@ -588,6 +588,21 @@ public class coreTest extends OpenCVTestCase {
...
@@ -588,6 +588,21 @@ public class coreTest extends OpenCVTestCase {
core
.
min
(
gray0
,
gray255
,
dst
);
core
.
min
(
gray0
,
gray255
,
dst
);
assertMatEqual
(
gray0
,
dst
);
assertMatEqual
(
gray0
,
dst
);
}
}
public
void
testMinMaxLoc
()
{
double
minVal
=
1
;
double
maxVal
=
10
;
Point
minLoc
=
new
Point
((
int
)
matSize
/
4
,
(
int
)
matSize
/
2
);
Point
maxLoc
=
new
Point
((
int
)
matSize
/
2
,
(
int
)
matSize
/
4
);
gray3
.
put
((
int
)
minLoc
.
y
,
(
int
)
minLoc
.
x
,
minVal
);
gray3
.
put
((
int
)
maxLoc
.
y
,
(
int
)
maxLoc
.
x
,
maxVal
);
core
.
MinMaxLocResult
mmres
=
core
.
minMaxLoc
(
gray3
);
assertTrue
(
mmres
.
minVal
==
minVal
&&
mmres
.
maxVal
==
maxVal
&&
mmres
.
minLoc
.
equals
(
minLoc
)
&&
mmres
.
maxLoc
.
equals
(
maxLoc
));
}
public
void
testMulSpectrumsMatMatMatInt
()
{
public
void
testMulSpectrumsMatMatMatInt
()
{
//TODO: nice example
//TODO: nice example
...
...
modules/java/gen_java.py
View file @
510ca536
...
@@ -96,6 +96,8 @@ type_dict = {
...
@@ -96,6 +96,8 @@ type_dict = {
}
}
setManualFunctions
=
set
([
'minMaxLoc'
])
class
ConstInfo
(
object
):
class
ConstInfo
(
object
):
def
__init__
(
self
,
cname
,
name
,
val
):
def
__init__
(
self
,
cname
,
name
,
val
):
## self.name = re.sub(r"^cv\.", "", name).replace(".", "_")
## self.name = re.sub(r"^cv\.", "", name).replace(".", "_")
...
@@ -239,6 +241,9 @@ class JavaWrapperGenerator(object):
...
@@ -239,6 +241,9 @@ class JavaWrapperGenerator(object):
def
add_func
(
self
,
decl
):
def
add_func
(
self
,
decl
):
ffi
=
FuncFamilyInfo
(
decl
)
ffi
=
FuncFamilyInfo
(
decl
)
if
ffi
.
jname
in
setManualFunctions
:
print
"Found function, which is ported manually: "
+
ffi
.
jname
return
None
func_map
=
self
.
funcs
func_map
=
self
.
funcs
classname
=
ffi
.
funcs
[
0
]
.
classname
classname
=
ffi
.
funcs
[
0
]
.
classname
if
classname
:
if
classname
:
...
@@ -293,6 +298,43 @@ class JavaWrapperGenerator(object):
...
@@ -293,6 +298,43 @@ class JavaWrapperGenerator(object):
CV_64F = 6,
CV_64F = 6,
CV_USRTYPE1 = 7;
CV_USRTYPE1 = 7;
//Manual ported functions
// C++: minMaxLoc(Mat src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0, InputArray mask=noArray())
//javadoc: minMaxLoc
public static class MinMaxLocResult {
public double minVal;
public double maxVal;
public Point minLoc;
public Point maxLoc;
public MinMaxLocResult() {
minVal=0; maxVal=0;
minLoc=new Point();
maxLoc=new Point();
}
}
public static MinMaxLocResult minMaxLoc(Mat src, Mat mask) {
MinMaxLocResult res = new MinMaxLocResult();
long maskNativeObj=0;
if (mask != null) {
maskNativeObj=mask.nativeObj;
}
double resarr[] = n_minMaxLoc(src.nativeObj, maskNativeObj);
res.minVal=resarr[0];
res.maxVal=resarr[1];
res.minLoc.x=resarr[2];
res.minLoc.y=resarr[3];
res.maxLoc.x=resarr[4];
res.maxLoc.y=resarr[5];
return res;
}
public static MinMaxLocResult minMaxLoc(Mat src) {
return minMaxLoc(src, null);
}
private static native double[] n_minMaxLoc(long src_nativeObj, long mask_nativeObj);
"""
)
"""
)
if
module
==
"imgproc"
:
if
module
==
"imgproc"
:
...
@@ -375,6 +417,65 @@ class JavaWrapperGenerator(object):
...
@@ -375,6 +417,65 @@ class JavaWrapperGenerator(object):
# step 4: generate code for the classes
# step 4: generate code for the classes
self
.
gen_classes
()
self
.
gen_classes
()
if
module
==
"core"
:
self
.
cpp_code
.
write
(
\
"""
JNIEXPORT jdoubleArray JNICALL Java_org_opencv_core_n_1minMaxLoc
(JNIEnv* env, jclass cls, jlong src_nativeObj, jlong mask_nativeObj)
{
try {
#ifdef DEBUG
LOGD("core::n_1minMaxLoc()");
#endif // DEBUG
jdoubleArray result;
result = env->NewDoubleArray(6);
if (result == NULL) {
return NULL; /* out of memory error thrown */
}
Mat& src = *((Mat*)src_nativeObj);
double minVal, maxVal;
Point minLoc, maxLoc;
if (mask_nativeObj != 0) {
Mat& mask = *((Mat*)mask_nativeObj);
minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc, mask);
} else {
minMaxLoc(src, &minVal, &maxVal, &minLoc, &maxLoc);
}
jdouble fill[6];
fill[0]=minVal;
fill[1]=maxVal;
fill[2]=minLoc.x;
fill[3]=minLoc.y;
fill[4]=maxLoc.x;
fill[5]=maxLoc.y;
env->SetDoubleArrayRegion(result, 0, 6, fill);
return result;
} catch(cv::Exception e) {
#ifdef DEBUG
LOGD("core::n_1minMaxLoc() catched cv::Exception:
%
s", e.what());
#endif // DEBUG
jclass je = env->FindClass("org/opencv/CvException");
if(!je) je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, e.what());
return NULL;
} catch (...) {
#ifdef DEBUG
LOGD("core::n_1minMaxLoc() catched unknown exception (...)");
#endif // DEBUG
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "Unknown exception in JNI code {$module::$fname()}");
return NULL;
}
}
"""
)
# module tail
# module tail
self
.
java_code
.
write
(
"
\n\n
"
+
self
.
jn_code
.
getvalue
()
+
"
\n
"
)
self
.
java_code
.
write
(
"
\n\n
"
+
self
.
jn_code
.
getvalue
()
+
"
\n
"
)
self
.
java_code
.
write
(
"}
\n
"
)
self
.
java_code
.
write
(
"}
\n
"
)
...
...
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