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
472820d8
Commit
472820d8
authored
Aug 03, 2011
by
Andrey Kamaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Java API: added tests for BruteForceMatcher (L2)
parent
3fac5d54
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
255 additions
and
33 deletions
+255
-33
OpenCVTestCase.java
...java/android_test/src/org/opencv/test/OpenCVTestCase.java
+20
-9
BruteForceDescriptorMatcherTest.java
...encv/test/features2d/BruteForceDescriptorMatcherTest.java
+226
-0
FASTFeatureDetectorTest.java
...c/org/opencv/test/features2d/FASTFeatureDetectorTest.java
+3
-8
STARFeatureDetectorTest.java
...c/org/opencv/test/features2d/STARFeatureDetectorTest.java
+3
-8
SURFFeatureDetectorTest.java
...c/org/opencv/test/features2d/SURFFeatureDetectorTest.java
+3
-8
No files found.
modules/java/android_test/src/org/opencv/test/OpenCVTestCase.java
View file @
472820d8
...
...
@@ -6,6 +6,7 @@ import org.opencv.core.Mat;
import
org.opencv.core.Point
;
import
org.opencv.core.Rect
;
import
org.opencv.core.Scalar
;
import
org.opencv.features2d.DMatch
;
import
org.opencv.features2d.KeyPoint
;
import
org.opencv.highgui.Highgui
;
...
...
@@ -200,15 +201,6 @@ public class OpenCVTestCase extends TestCase {
assertPointEquals
(
list1
.
get
(
i
),
list2
.
get
(
i
),
epsilon
);
}
public
static
void
assertListKeyPointEquals
(
List
<
KeyPoint
>
list1
,
List
<
KeyPoint
>
list2
,
double
epsilon
)
{
if
(
list1
.
size
()
!=
list2
.
size
())
{
throw
new
UnsupportedOperationException
();
}
for
(
int
i
=
0
;
i
<
list1
.
size
();
i
++)
assertKeyPointEqual
(
list1
.
get
(
i
),
list2
.
get
(
i
),
epsilon
);
}
public
static
void
assertListRectEquals
(
List
<
Rect
>
list1
,
List
<
Rect
>
list2
)
{
if
(
list1
.
size
()
!=
list2
.
size
())
{
throw
new
UnsupportedOperationException
();
...
...
@@ -249,6 +241,25 @@ public class OpenCVTestCase extends TestCase {
assertEquals
(
expected
.
octave
,
actual
.
octave
);
assertEquals
(
expected
.
class_id
,
actual
.
class_id
);
}
public
static
void
assertListKeyPointEquals
(
List
<
KeyPoint
>
expected
,
List
<
KeyPoint
>
actual
,
double
epsilon
)
{
assertEquals
(
expected
.
size
(),
actual
.
size
());
for
(
int
i
=
0
;
i
<
expected
.
size
();
i
++)
assertKeyPointEqual
(
expected
.
get
(
i
),
actual
.
get
(
i
),
epsilon
);
}
public
static
void
assertDMatchEqual
(
DMatch
expected
,
DMatch
actual
,
double
eps
)
{
assertEquals
(
expected
.
queryIdx
,
actual
.
queryIdx
);
assertEquals
(
expected
.
trainIdx
,
actual
.
trainIdx
);
assertEquals
(
expected
.
imgIdx
,
actual
.
imgIdx
);
assertTrue
(
Math
.
abs
(
expected
.
distance
-
actual
.
distance
)
<
eps
);
}
public
static
void
assertListDMatchEquals
(
List
<
DMatch
>
expected
,
List
<
DMatch
>
actual
,
double
epsilon
)
{
assertEquals
(
expected
.
size
(),
actual
.
size
());
for
(
int
i
=
0
;
i
<
expected
.
size
();
i
++)
assertDMatchEqual
(
expected
.
get
(
i
),
actual
.
get
(
i
),
epsilon
);
}
public
static
void
assertPointEquals
(
Point
expected
,
Point
actual
,
double
eps
)
{
assertEquals
(
expected
.
x
,
actual
.
x
,
eps
);
...
...
modules/java/android_test/src/org/opencv/test/features2d/BruteForceDescriptorMatcherTest.java
0 → 100644
View file @
472820d8
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.DMatch
;
import
org.opencv.features2d.DescriptorExtractor
;
import
org.opencv.features2d.DescriptorMatcher
;
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.Arrays
;
import
java.util.List
;
public
class
BruteForceDescriptorMatcherTest
extends
OpenCVTestCase
{
DescriptorMatcher
matcher
;
int
matSize
;
DMatch
[]
truth
;
protected
void
setUp
()
throws
Exception
{
matcher
=
DescriptorMatcher
.
create
(
DescriptorMatcher
.
BRUTEFORCE
);
matSize
=
100
;
truth
=
new
DMatch
[]
{
new
DMatch
(
0
,
0
,
0
,
0.643284f
),
new
DMatch
(
1
,
1
,
0
,
0.92945856f
),
new
DMatch
(
2
,
1
,
0
,
0.2841479f
),
new
DMatch
(
3
,
1
,
0
,
0.9194034f
),
new
DMatch
(
4
,
1
,
0
,
0.3006621f
)
};
super
.
setUp
();
}
private
Mat
getTrainImg
()
{
Mat
cross
=
new
Mat
(
matSize
,
matSize
,
CvType
.
CV_8U
,
new
Scalar
(
255
));
Core
.
line
(
cross
,
new
Point
(
20
,
matSize
/
2
),
new
Point
(
matSize
-
21
,
matSize
/
2
),
new
Scalar
(
100
),
2
);
Core
.
line
(
cross
,
new
Point
(
matSize
/
2
,
20
),
new
Point
(
matSize
/
2
,
matSize
-
21
),
new
Scalar
(
100
),
2
);
return
cross
;
}
private
Mat
getQueryImg
()
{
Mat
cross
=
new
Mat
(
matSize
,
matSize
,
CvType
.
CV_8U
,
new
Scalar
(
255
));
Core
.
line
(
cross
,
new
Point
(
30
,
matSize
/
2
),
new
Point
(
matSize
-
31
,
matSize
/
2
),
new
Scalar
(
100
),
3
);
Core
.
line
(
cross
,
new
Point
(
matSize
/
2
,
30
),
new
Point
(
matSize
/
2
,
matSize
-
31
),
new
Scalar
(
100
),
3
);
return
cross
;
}
private
Mat
getQueryDescriptors
()
{
Mat
img
=
getQueryImg
();
List
<
KeyPoint
>
keypoints
=
new
ArrayList
<
KeyPoint
>();
Mat
descriptors
=
new
Mat
();
FeatureDetector
detector
=
FeatureDetector
.
create
(
FeatureDetector
.
SURF
);
DescriptorExtractor
extractor
=
DescriptorExtractor
.
create
(
DescriptorExtractor
.
SURF
);
String
filename
=
OpenCVTestRunner
.
getTempFileName
(
"yml"
);
writeFile
(
filename
,
"%YAML:1.0\nhessianThreshold: 8000.\noctaves: 3\noctaveLayers: 4\nupright: 0\n"
);
detector
.
read
(
filename
);
detector
.
detect
(
img
,
keypoints
);
OpenCVTestRunner
.
Log
(
"points found: "
+
keypoints
.
size
());
for
(
KeyPoint
kp
:
keypoints
)
OpenCVTestRunner
.
Log
(
kp
.
toString
());
extractor
.
compute
(
img
,
keypoints
,
descriptors
);
return
descriptors
;
}
private
Mat
getTrainDescriptors
()
{
Mat
img
=
getTrainImg
();
List
<
KeyPoint
>
keypoints
=
Arrays
.
asList
(
new
KeyPoint
(
50
,
50
,
16
,
0
,
20000
,
1
,
-
1
),
new
KeyPoint
(
42
,
42
,
16
,
160
,
10000
,
1
,
-
1
));
Mat
descriptors
=
new
Mat
();
DescriptorExtractor
extractor
=
DescriptorExtractor
.
create
(
DescriptorExtractor
.
SURF
);
extractor
.
compute
(
img
,
keypoints
,
descriptors
);
return
descriptors
;
}
private
Mat
getMaskImg
()
{
return
new
Mat
(
5
,
2
,
CvType
.
CV_8U
,
new
Scalar
(
0
))
{
{
put
(
0
,
0
,
1
,
1
,
1
,
1
);
}
};
}
public
void
testAdd
()
{
matcher
.
add
(
Arrays
.
asList
(
new
Mat
()));
assertFalse
(
matcher
.
empty
());
}
public
void
testClear
()
{
matcher
.
add
(
Arrays
.
asList
(
new
Mat
()));
matcher
.
clear
();
assertTrue
(
matcher
.
empty
());
}
public
void
testCloneBoolean
()
{
matcher
.
add
(
Arrays
.
asList
(
new
Mat
()));
DescriptorMatcher
cloned
=
matcher
.
clone
(
true
);
assertNotNull
(
cloned
);
assertTrue
(
cloned
.
empty
());
}
public
void
testClone
()
{
Mat
train
=
new
Mat
(
1
,
1
,
CvType
.
CV_8U
,
new
Scalar
(
123
));
Mat
truth
=
train
.
clone
();
matcher
.
add
(
Arrays
.
asList
(
train
));
DescriptorMatcher
cloned
=
matcher
.
clone
();
assertNotNull
(
cloned
);
List
<
Mat
>
descriptors
=
cloned
.
getTrainDescriptors
();
assertEquals
(
1
,
descriptors
.
size
());
assertMatEqual
(
truth
,
descriptors
.
get
(
0
));
}
public
void
testCreate
()
{
assertNotNull
(
matcher
);
}
public
void
testEmpty
()
{
assertTrue
(
matcher
.
empty
());
}
public
void
testGetTrainDescriptors
()
{
Mat
train
=
new
Mat
(
1
,
1
,
CvType
.
CV_8U
,
new
Scalar
(
123
));
Mat
truth
=
train
.
clone
();
matcher
.
add
(
Arrays
.
asList
(
train
));
List
<
Mat
>
descriptors
=
matcher
.
getTrainDescriptors
();
assertEquals
(
1
,
descriptors
.
size
());
assertMatEqual
(
truth
,
descriptors
.
get
(
0
));
}
public
void
testIsMaskSupported
()
{
assertTrue
(
matcher
.
isMaskSupported
());
}
public
void
testMatchMatMatListOfDMatchMat
()
{
Mat
train
=
getTrainDescriptors
();
Mat
query
=
getQueryDescriptors
();
Mat
mask
=
getMaskImg
();
List
<
DMatch
>
matches
=
new
ArrayList
<
DMatch
>();
matcher
.
match
(
query
,
train
,
matches
,
mask
);
assertListDMatchEquals
(
Arrays
.
asList
(
truth
[
0
],
truth
[
1
]),
matches
,
EPS
);
}
public
void
testMatchMatMatListOfDMatch
()
{
Mat
train
=
getTrainDescriptors
();
Mat
query
=
getQueryDescriptors
();
List
<
DMatch
>
matches
=
new
ArrayList
<
DMatch
>();
matcher
.
match
(
query
,
train
,
matches
);
assertListDMatchEquals
(
Arrays
.
asList
(
truth
),
matches
,
EPS
);
// OpenCVTestRunner.Log("matches found: " + matches.size());
// for (DMatch m : matches)
// OpenCVTestRunner.Log(m.toString());
}
public
void
testMatchMatListOfDMatchListOfMat
()
{
Mat
train
=
getTrainDescriptors
();
Mat
query
=
getQueryDescriptors
();
Mat
mask
=
getMaskImg
();
List
<
DMatch
>
matches
=
new
ArrayList
<
DMatch
>();
matcher
.
add
(
Arrays
.
asList
(
train
));
matcher
.
match
(
query
,
matches
,
Arrays
.
asList
(
mask
));
assertListDMatchEquals
(
Arrays
.
asList
(
truth
[
0
],
truth
[
1
]),
matches
,
EPS
);
}
public
void
testMatchMatListOfDMatch
()
{
Mat
train
=
getTrainDescriptors
();
Mat
query
=
getQueryDescriptors
();
List
<
DMatch
>
matches
=
new
ArrayList
<
DMatch
>();
matcher
.
add
(
Arrays
.
asList
(
train
));
matcher
.
match
(
query
,
matches
);
assertListDMatchEquals
(
Arrays
.
asList
(
truth
),
matches
,
EPS
);
}
public
void
testRead
()
{
String
filename
=
OpenCVTestRunner
.
getTempFileName
(
"yml"
);
writeFile
(
filename
,
"%YAML:1.0\n"
);
matcher
.
read
(
filename
);
assertTrue
(
true
);
// BruteforceMatcher has no settings
}
public
void
testTrain
()
{
matcher
.
train
();
// BruteforceMatcher does not need to train
}
public
void
testWrite
()
{
String
filename
=
OpenCVTestRunner
.
getTempFileName
(
"yml"
);
matcher
.
write
(
filename
);
String
truth
=
"%YAML:1.0\n"
;
assertEquals
(
truth
,
readFile
(
filename
));
}
}
modules/java/android_test/src/org/opencv/test/features2d/FASTFeatureDetectorTest.java
View file @
472820d8
...
...
@@ -11,6 +11,7 @@ import org.opencv.test.OpenCVTestCase;
import
org.opencv.test.OpenCVTestRunner
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
FASTFeatureDetectorTest
extends
OpenCVTestCase
{
...
...
@@ -52,11 +53,7 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
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
);
assertListKeyPointEquals
(
Arrays
.
asList
(
truth
[
0
],
truth
[
1
]),
keypoints
,
EPS
);
}
public
void
testDetectMatListOfKeyPoint
()
{
...
...
@@ -65,9 +62,7 @@ public class FASTFeatureDetectorTest extends OpenCVTestCase {
detector
.
detect
(
img
,
keypoints
);
assertEquals
(
truth
.
length
,
keypoints
.
size
());
for
(
int
i
=
0
;
i
<
truth
.
length
;
i
++)
assertKeyPointEqual
(
truth
[
i
],
keypoints
.
get
(
i
),
EPS
);
assertListKeyPointEquals
(
Arrays
.
asList
(
truth
),
keypoints
,
EPS
);
// OpenCVTestRunner.Log("points found: " + keypoints.size());
// for (KeyPoint kp : keypoints)
...
...
modules/java/android_test/src/org/opencv/test/features2d/STARFeatureDetectorTest.java
View file @
472820d8
...
...
@@ -11,6 +11,7 @@ import org.opencv.test.OpenCVTestCase;
import
org.opencv.test.OpenCVTestRunner
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
STARFeatureDetectorTest
extends
OpenCVTestCase
{
...
...
@@ -71,11 +72,7 @@ public class STARFeatureDetectorTest extends OpenCVTestCase {
detector
.
detect
(
img
,
keypoints
,
mask
);
KeyPoint
[]
_truth
=
new
KeyPoint
[]
{
truth
[
0
],
truth
[
2
],
truth
[
5
],
truth
[
7
]
};
assertEquals
(
_truth
.
length
,
keypoints
.
size
());
for
(
int
i
=
0
;
i
<
_truth
.
length
;
i
++)
assertKeyPointEqual
(
_truth
[
i
],
keypoints
.
get
(
i
),
EPS
);
assertListKeyPointEquals
(
Arrays
.
asList
(
truth
[
0
],
truth
[
2
],
truth
[
5
],
truth
[
7
]),
keypoints
,
EPS
);
}
public
void
testDetectMatListOfKeyPoint
()
{
...
...
@@ -84,9 +81,7 @@ public class STARFeatureDetectorTest extends OpenCVTestCase {
detector
.
detect
(
img
,
keypoints
);
assertEquals
(
truth
.
length
,
keypoints
.
size
());
for
(
int
i
=
0
;
i
<
truth
.
length
;
i
++)
assertKeyPointEqual
(
truth
[
i
],
keypoints
.
get
(
i
),
EPS
);
assertListKeyPointEquals
(
Arrays
.
asList
(
truth
),
keypoints
,
EPS
);
}
public
void
testEmpty
()
{
...
...
modules/java/android_test/src/org/opencv/test/features2d/SURFFeatureDetectorTest.java
View file @
472820d8
...
...
@@ -11,6 +11,7 @@ import org.opencv.test.OpenCVTestCase;
import
org.opencv.test.OpenCVTestRunner
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.List
;
...
...
@@ -77,12 +78,8 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase {
detector
.
detect
(
img
,
keypoints
,
mask
);
KeyPoint
[]
_truth
=
new
KeyPoint
[]
{
truth
[
1
],
truth
[
2
]
};
assertEquals
(
_truth
.
length
,
keypoints
.
size
());
order
(
keypoints
);
for
(
int
i
=
0
;
i
<
_truth
.
length
;
i
++)
assertKeyPointEqual
(
_truth
[
i
],
keypoints
.
get
(
i
),
EPS
);
assertListKeyPointEquals
(
Arrays
.
asList
(
truth
[
1
],
truth
[
2
]),
keypoints
,
EPS
);
}
public
void
testDetectMatListOfKeyPoint
()
{
...
...
@@ -95,10 +92,8 @@ public class SURFFeatureDetectorTest extends OpenCVTestCase {
detector
.
detect
(
cross
,
keypoints
);
assertEquals
(
truth
.
length
,
keypoints
.
size
());
order
(
keypoints
);
for
(
int
i
=
0
;
i
<
truth
.
length
;
i
++)
assertKeyPointEqual
(
truth
[
i
],
keypoints
.
get
(
i
),
EPS
);
assertListKeyPointEquals
(
Arrays
.
asList
(
truth
),
keypoints
,
EPS
);
}
public
void
testEmpty
()
{
...
...
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