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
99b8e2db
Commit
99b8e2db
authored
Aug 02, 2011
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Java API: added tests for FAST feature detector
parent
bba4f9e5
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
229 additions
and
15 deletions
+229
-15
CMakeLists.txt
CMakeLists.txt
+1
-1
OpenCVTestCase.java
...java/android_test/src/org/opencv/test/OpenCVTestCase.java
+54
-5
OpenCVTestRunner.java
...va/android_test/src/org/opencv/test/OpenCVTestRunner.java
+19
-0
FASTFeatureDetectorTest.java
...c/org/opencv/test/features2d/FASTFeatureDetectorTest.java
+145
-0
gen_java.py
modules/java/gen_java.py
+1
-0
features2d_manual.hpp
modules/java/src/cpp/features2d_manual.hpp
+9
-9
No files found.
CMakeLists.txt
View file @
99b8e2db
...
...
@@ -829,7 +829,7 @@ if (BUILD_JAVA_SUPPORT)
endif
()
if
(
CAN_BUILD_ANDROID_PROJECTS
)
option
(
BUILD_ANDROID_EXAMPLES
"Build examples for Android platform"
TRUE
)
SET
(
BUILD_ANDROID_EXAMPLES TRUE CACHE BOOL
"Build examples for Android platform"
)
endif
()
#YV
...
...
modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java
View file @
99b8e2db
package
org
.
opencv
.
test
;
import
java.util.List
;
import
junit.framework.TestCase
;
import
org.opencv.core.Core
;
import
org.opencv.core.CvType
;
import
org.opencv.core.Mat
;
import
org.opencv.core.Point
;
import
org.opencv.core.Rect
;
import
org.opencv.core.Scalar
;
import
org.opencv.core.Core
;
import
org.opencv.features2d.KeyPoint
;
import
org.opencv.highgui.Highgui
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.nio.MappedByteBuffer
;
import
java.nio.channels.FileChannel
;
import
java.nio.charset.Charset
;
import
java.util.List
;
import
junit.framework.TestCase
;
public
class
OpenCVTestCase
extends
TestCase
{
protected
static
int
matSize
=
10
;
...
...
@@ -296,4 +303,46 @@ public class OpenCVTestCase extends TestCase {
OpenCVTestRunner
.
Log
(
"================================================"
);
OpenCVTestRunner
.
Log
(
"=============== "
+
label
);
}
protected
static
String
readFile
(
String
path
)
{
FileInputStream
stream
=
null
;
try
{
stream
=
new
FileInputStream
(
new
File
(
path
));
FileChannel
fc
=
stream
.
getChannel
();
MappedByteBuffer
bb
=
fc
.
map
(
FileChannel
.
MapMode
.
READ_ONLY
,
0
,
fc
.
size
());
return
Charset
.
defaultCharset
().
decode
(
bb
).
toString
();
}
catch
(
IOException
e
)
{
OpenCVTestRunner
.
Log
(
"Failed to read file \""
+
path
+
"\". Exception is thrown: "
+
e
);
return
null
;
}
finally
{
if
(
stream
!=
null
)
try
{
stream
.
close
();
}
catch
(
IOException
e
)
{
OpenCVTestRunner
.
Log
(
"Exception is thrown: "
+
e
);
}
}
}
protected
static
void
writeFile
(
String
path
,
String
content
)
{
FileOutputStream
stream
=
null
;
try
{
stream
=
new
FileOutputStream
(
new
File
(
path
));
FileChannel
fc
=
stream
.
getChannel
();
fc
.
write
(
Charset
.
defaultCharset
().
encode
(
content
));
}
catch
(
IOException
e
)
{
OpenCVTestRunner
.
Log
(
"Failed to write file \""
+
path
+
"\". Exception is thrown: "
+
e
);
}
finally
{
if
(
stream
!=
null
)
try
{
stream
.
close
();
}
catch
(
IOException
e
)
{
OpenCVTestRunner
.
Log
(
"Exception is thrown: "
+
e
);
}
}
}
}
modules/java/android_test/src/org/opencv/test/OpenCVTestRunner.java
View file @
99b8e2db
...
...
@@ -7,6 +7,9 @@ import android.util.Log;
import
org.opencv.Android
;
import
java.io.File
;
import
java.io.IOException
;
/**
* This only class is Android specific. The original idea about test order
* randomization is from marek.defecinski blog.
...
...
@@ -24,6 +27,22 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
private
AndroidTestRunner
androidTestRunner
;
private
static
String
TAG
=
"opencv_test_java"
;
public
static
String
getTempFileName
(
String
extension
)
{
File
cache
=
context
.
getCacheDir
();
if
(!
extension
.
startsWith
(
"."
))
extension
=
"."
+
extension
;
try
{
File
tmp
=
File
.
createTempFile
(
"OpenCV"
,
extension
,
cache
);
String
path
=
tmp
.
getAbsolutePath
();
tmp
.
delete
();
return
path
;
}
catch
(
IOException
e
)
{
Log
(
"Failed to get temp file name. Exception is thrown: "
+
e
);
}
return
null
;
}
static
public
void
Log
(
String
message
)
{
Log
.
e
(
TAG
,
message
);
}
...
...
modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java
0 → 100644
View file @
99b8e2db
package
org
.
opencv
.
test
.
features2d
;
import
org.opencv.core.Core
;
import
org.opencv.core.CvType
;
import
org.opencv.core.Mat
;
import
org.opencv.core.Point
;
import
org.opencv.core.Scalar
;
import
org.opencv.features2d.FeatureDetector
;
import
org.opencv.features2d.KeyPoint
;
import
org.opencv.test.OpenCVTestCase
;
import
org.opencv.test.OpenCVTestRunner
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
FASTFeatureDetectorTest
extends
OpenCVTestCase
{
FeatureDetector
detector
;
KeyPoint
[]
truth
;
@Override
protected
void
setUp
()
throws
Exception
{
detector
=
FeatureDetector
.
create
(
FeatureDetector
.
FAST
);
truth
=
new
KeyPoint
[]
{
new
KeyPoint
(
32
,
27
,
6
,
-
1
,
254
,
0
,
-
1
),
new
KeyPoint
(
27
,
32
,
6
,
-
1
,
254
,
0
,
-
1
),
new
KeyPoint
(
73
,
68
,
6
,
-
1
,
254
,
0
,
-
1
),
new
KeyPoint
(
68
,
73
,
6
,
-
1
,
254
,
0
,
-
1
)
};
super
.
setUp
();
}
private
Mat
getTestImg
()
{
Mat
img
=
new
Mat
(
100
,
100
,
CvType
.
CV_8U
,
new
Scalar
(
255
));
Core
.
line
(
img
,
new
Point
(
30
,
30
),
new
Point
(
70
,
70
),
new
Scalar
(
0
),
8
);
return
img
;
}
private
Mat
getMaskImg
()
{
Mat
mask
=
new
Mat
(
100
,
100
,
CvType
.
CV_8U
,
new
Scalar
(
255
));
Mat
right
=
mask
.
submat
(
0
,
100
,
50
,
100
);
right
.
setTo
(
new
Scalar
(
0
));
return
mask
;
}
public
void
testCreate
()
{
assertNotNull
(
detector
);
}
public
void
testDetectMatListOfKeyPointMat
()
{
Mat
img
=
getTestImg
();
Mat
mask
=
getMaskImg
();
List
<
KeyPoint
>
keypoints
=
new
ArrayList
<
KeyPoint
>();
detector
.
detect
(
img
,
keypoints
,
mask
);
KeyPoint
[]
_truth
=
new
KeyPoint
[]
{
truth
[
0
],
truth
[
1
]
};
assertEquals
(
_truth
.
length
,
keypoints
.
size
());
for
(
int
i
=
0
;
i
<
_truth
.
length
;
i
++)
assertKeyPointEqual
(
_truth
[
i
],
keypoints
.
get
(
i
),
EPS
);
}
public
void
testDetectMatListOfKeyPoint
()
{
Mat
img
=
getTestImg
();
List
<
KeyPoint
>
keypoints
=
new
ArrayList
<
KeyPoint
>();
detector
.
detect
(
img
,
keypoints
);
assertEquals
(
truth
.
length
,
keypoints
.
size
());
for
(
int
i
=
0
;
i
<
truth
.
length
;
i
++)
assertKeyPointEqual
(
truth
[
i
],
keypoints
.
get
(
i
),
EPS
);
// OpenCVTestRunner.Log("points found: " + keypoints.size());
// for (KeyPoint kp : keypoints)
// OpenCVTestRunner.Log(kp.toString());
}
public
void
testEmpty
()
{
assertFalse
(
detector
.
empty
());
}
public
void
testRead
()
{
String
filename
=
OpenCVTestRunner
.
getTempFileName
(
"yml"
);
writeFile
(
filename
,
"%YAML:1.0\nthreshold: 130\nnonmaxSuppression: 1\n"
);
detector
.
read
(
filename
);
List
<
KeyPoint
>
keypoints1
=
new
ArrayList
<
KeyPoint
>();
detector
.
detect
(
grayChess
,
keypoints1
);
writeFile
(
filename
,
"%YAML:1.0\nthreshold: 150\nnonmaxSuppression: 1\n"
);
detector
.
read
(
filename
);
List
<
KeyPoint
>
keypoints2
=
new
ArrayList
<
KeyPoint
>();
detector
.
detect
(
grayChess
,
keypoints2
);
assertTrue
(
keypoints2
.
size
()
<=
keypoints1
.
size
());
}
public
void
testReadYml
()
{
String
filename
=
OpenCVTestRunner
.
getTempFileName
(
"yml"
);
writeFile
(
filename
,
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>130</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n"
);
detector
.
read
(
filename
);
List
<
KeyPoint
>
keypoints1
=
new
ArrayList
<
KeyPoint
>();
detector
.
detect
(
grayChess
,
keypoints1
);
writeFile
(
filename
,
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>150</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n"
);
detector
.
read
(
filename
);
List
<
KeyPoint
>
keypoints2
=
new
ArrayList
<
KeyPoint
>();
detector
.
detect
(
grayChess
,
keypoints2
);
assertTrue
(
keypoints2
.
size
()
<=
keypoints1
.
size
());
}
public
void
testWrite
()
{
String
filename
=
OpenCVTestRunner
.
getTempFileName
(
"xml"
);
detector
.
write
(
filename
);
String
truth
=
"<?xml version=\"1.0\"?>\n<opencv_storage>\n<threshold>10</threshold>\n<nonmaxSuppression>1</nonmaxSuppression>\n</opencv_storage>\n"
;
assertEquals
(
truth
,
readFile
(
filename
));
}
public
void
testWriteYml
()
{
String
filename
=
OpenCVTestRunner
.
getTempFileName
(
"yml"
);
detector
.
write
(
filename
);
String
truth
=
"%YAML:1.0\nthreshold: 10\nnonmaxSuppression: 1\n"
;
assertEquals
(
truth
,
readFile
(
filename
));
}
}
modules/java/gen_java.py
View file @
99b8e2db
...
...
@@ -13,6 +13,7 @@ class_ignore_list = (
"VideoWriter"
,
"VideoCapture"
,
#features2d
"KeyPoint"
,
"MSER"
,
)
const_ignore_list
=
(
...
...
modules/java/src/cpp/features2d_manual.hpp
View file @
99b8e2db
...
...
@@ -10,8 +10,8 @@ class CV_EXPORTS_AS(FeatureDetector) javaFeatureDetector : public FeatureDetecto
{
public
:
#if 0
CV_WRAP void detect( const Mat& image, vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
CV_WRAP void detect( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, const vector<Mat>& masks=vector<Mat>() ) const;
CV_WRAP void detect( const Mat& image,
CV_OUT
vector<KeyPoint>& keypoints, const Mat& mask=Mat() ) const;
CV_WRAP void detect( const vector<Mat>& images,
CV_OUT
vector<vector<KeyPoint> >& keypoints, const vector<Mat>& masks=vector<Mat>() ) const;
CV_WRAP virtual bool empty() const;
#endif
...
...
@@ -145,18 +145,18 @@ public:
CV_WRAP virtual bool empty() const;
CV_WRAP virtual void train();
CV_WRAP void match( const Mat& queryDescriptors, const Mat& trainDescriptors,
vector<DMatch>& matches, const Mat& mask=Mat() ) const;
CV_OUT
vector<DMatch>& matches, const Mat& mask=Mat() ) const;
CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
vector<vector<DMatch> >& matches, int k,
CV_OUT
vector<vector<DMatch> >& matches, int k,
const Mat& mask=Mat(), bool compactResult=false ) const;
CV_WRAP void radiusMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
vector<vector<DMatch> >& matches, float maxDistance,
CV_OUT
vector<vector<DMatch> >& matches, float maxDistance,
const Mat& mask=Mat(), bool compactResult=false ) const;
CV_WRAP void match( const Mat& queryDescriptors, vector<DMatch>& matches,
CV_WRAP void match( const Mat& queryDescriptors,
CV_OUT
vector<DMatch>& matches,
const vector<Mat>& masks=vector<Mat>() );
CV_WRAP void knnMatch( const Mat& queryDescriptors, vector<vector<DMatch> >& matches, int k,
CV_WRAP void knnMatch( const Mat& queryDescriptors,
CV_OUT
vector<vector<DMatch> >& matches, int k,
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
CV_WRAP void radiusMatch( const Mat& queryDescriptors, vector<vector<DMatch> >& matches, float maxDistance,
CV_WRAP void radiusMatch( const Mat& queryDescriptors,
CV_OUT
vector<vector<DMatch> >& matches, float maxDistance,
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
#endif
...
...
@@ -229,7 +229,7 @@ class CV_EXPORTS_AS(DescriptorExtractor) javaDescriptorExtractor : public Descri
public
:
#if 0
CV_WRAP void compute( const Mat& image, vector<KeyPoint>& keypoints, Mat& descriptors ) const;
CV_WRAP void compute( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints, vector<Mat>& descriptors ) const;
CV_WRAP void compute( const vector<Mat>& images, vector<vector<KeyPoint> >& keypoints,
CV_OUT
vector<Mat>& descriptors ) const;
CV_WRAP virtual int descriptorSize() const = 0;
CV_WRAP virtual int descriptorType() const = 0;
...
...
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