Skip to content

Commit 2561c59

Browse files
committed
Merge pull request opencv#8524 from mshabunin:java-fixes
2 parents fd93ae0 + 4d62f1d commit 2561c59

File tree

5 files changed

+61
-7
lines changed

5 files changed

+61
-7
lines changed

modules/core/misc/java/src/java/core+DMatch.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@ public DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance) {
4545
distance = _distance;
4646
}
4747

48-
/**
49-
* Less is better.
50-
*/
5148
public boolean lessThan(DMatch it) {
5249
return distance < it.distance;
5350
}

modules/java/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ else(ANDROID)
345345
list(APPEND step3_depends "${OpenCV_BINARY_DIR}/build.xml")
346346
347347
add_custom_command(OUTPUT "${JAR_FILE}" "${JAR_FILE}.dephelper"
348-
COMMAND ${ANT_EXECUTABLE} -q -noinput -k jar
348+
COMMAND ${ANT_EXECUTABLE} -q -noinput -k jar javadoc
349349
COMMAND ${CMAKE_COMMAND} -E touch "${JAR_FILE}.dephelper"
350350
WORKING_DIRECTORY "${OpenCV_BINARY_DIR}"
351351
DEPENDS ${step3_depends}

modules/java/build.xml.in

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<!-- process, this config is used to package the autogenerated .java -->
33
<!-- interface files into OpenCV.jar -->
44
<project name="OpenCV">
5+
56
<target name="jar">
67
<!-- This is to make a jar with a source attachment, for e.g. easy -->
78
<!-- navigation in Eclipse. See this question: -->
@@ -10,7 +11,21 @@
1011
<include name="**/*.java"/>
1112
<compilerarg line="-encoding utf-8"/>
1213
</javac>
13-
1414
<jar basedir="src" destfile="bin/@JAR_NAME@"/>
1515
</target>
16+
17+
<target name="javadoc">
18+
<tstamp>
19+
<format property="doctimestamp" pattern="EEE MMM d yyyy HH:mm:ss z"/>
20+
</tstamp>
21+
<javadoc
22+
packagenames="org.opencv.*"
23+
sourcepath="src"
24+
destdir="doc/javadoc"
25+
Windowtitle="OpenCV @OPENCV_VERSION_PLAIN@ Java documentation"
26+
Doctitle="OpenCV Java documentation (@OPENCV_VERSION@)"
27+
bottom="Generated on ${doctimestamp} / OpenCV @OPENCV_VCSVERSION@"
28+
/>
29+
</target>
30+
1631
</project>

modules/java/generator/gen_java.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ def add_class(self, decl):
10051005
type_dict["Ptr_"+name] = \
10061006
{ "j_type" : classinfo.jname,
10071007
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
1008-
"jni_name" : "Ptr<"+classinfo.fullName(isCPP=True)+">(("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj)", "jni_type" : "jlong",
1008+
"jni_name" : "*((Ptr<"+classinfo.fullName(isCPP=True)+">*)%(n)s_nativeObj)", "jni_type" : "jlong",
10091009
"suffix" : "J" }
10101010
logging.info('ok: class %s, name: %s, base: %s', classinfo, name, classinfo.base)
10111011

@@ -1575,7 +1575,7 @@ def isSmartClass(self, ci):
15751575
# if parents are smart (we hope) then children are!
15761576
# if not we believe the class is smart if it has "create" method
15771577
ci.smart = False
1578-
if ci.base:
1578+
if ci.base or ci.name == 'Algorithm':
15791579
ci.smart = True
15801580
else:
15811581
for fi in ci.methods:

modules/ml/misc/java/test/MLTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.opencv.test.ml;
2+
3+
import org.opencv.ml.Ml;
4+
import org.opencv.ml.SVM;
5+
import org.opencv.core.Mat;
6+
import org.opencv.core.MatOfFloat;
7+
import org.opencv.core.MatOfInt;
8+
import org.opencv.core.CvType;
9+
import org.opencv.test.OpenCVTestCase;
10+
import org.opencv.test.OpenCVTestRunner;
11+
12+
public class MLTest extends OpenCVTestCase {
13+
14+
public void testSaveLoad() {
15+
Mat samples = new MatOfFloat(new float[] {
16+
5.1f, 3.5f, 1.4f, 0.2f,
17+
4.9f, 3.0f, 1.4f, 0.2f,
18+
4.7f, 3.2f, 1.3f, 0.2f,
19+
4.6f, 3.1f, 1.5f, 0.2f,
20+
5.0f, 3.6f, 1.4f, 0.2f,
21+
7.0f, 3.2f, 4.7f, 1.4f,
22+
6.4f, 3.2f, 4.5f, 1.5f,
23+
6.9f, 3.1f, 4.9f, 1.5f,
24+
5.5f, 2.3f, 4.0f, 1.3f,
25+
6.5f, 2.8f, 4.6f, 1.5f
26+
}).reshape(1, 10);
27+
Mat responses = new MatOfInt(new int[] {
28+
0, 0, 0, 0, 0, 1, 1, 1, 1, 1
29+
}).reshape(1, 10);
30+
SVM saved = SVM.create();
31+
assertFalse(saved.isTrained());
32+
33+
saved.train(samples, Ml.ROW_SAMPLE, responses);
34+
assertTrue(saved.isTrained());
35+
36+
String filename = OpenCVTestRunner.getTempFileName("yml");
37+
saved.save(filename);
38+
SVM loaded = SVM.load(filename);
39+
assertTrue(saved.isTrained());
40+
}
41+
42+
}

0 commit comments

Comments
 (0)