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
eaee63d9
Commit
eaee63d9
authored
Nov 03, 2018
by
berak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
java: add converters, tests for MatOfRotatedRect
parent
d9b8a9d9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
105 additions
and
1 deletion
+105
-1
Converters.java
.../java/generator/src/java/org/opencv/utils/Converters.java
+39
-0
OpenCVTestCase.java
...test/android_test/src/org/opencv/test/OpenCVTestCase.java
+19
-0
ConvertersTest.java
...common_test/src/org/opencv/test/utils/ConvertersTest.java
+28
-1
OpenCVTestCase.java
...va/test/pure_test/src/org/opencv/test/OpenCVTestCase.java
+19
-0
No files found.
modules/java/generator/src/java/org/opencv/utils/Converters.java
View file @
eaee63d9
...
...
@@ -13,7 +13,9 @@ import org.opencv.core.MatOfPoint2f;
import
org.opencv.core.MatOfPoint3f
;
import
org.opencv.core.Point
;
import
org.opencv.core.Point3
;
import
org.opencv.core.Size
;
import
org.opencv.core.Rect
;
import
org.opencv.core.RotatedRect
;
import
org.opencv.core.Rect2d
;
import
org.opencv.core.DMatch
;
import
org.opencv.core.KeyPoint
;
...
...
@@ -770,4 +772,41 @@ public class Converters {
}
mats
.
clear
();
}
public
static
Mat
vector_RotatedRect_to_Mat
(
List
<
RotatedRect
>
rs
)
{
Mat
res
;
int
count
=
(
rs
!=
null
)
?
rs
.
size
()
:
0
;
if
(
count
>
0
)
{
res
=
new
Mat
(
count
,
1
,
CvType
.
CV_32FC
(
5
));
float
[]
buff
=
new
float
[
5
*
count
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
RotatedRect
r
=
rs
.
get
(
i
);
buff
[
5
*
i
]
=
(
float
)
r
.
center
.
x
;
buff
[
5
*
i
+
1
]
=
(
float
)
r
.
center
.
y
;
buff
[
5
*
i
+
2
]
=
(
float
)
r
.
size
.
width
;
buff
[
5
*
i
+
3
]
=
(
float
)
r
.
size
.
height
;
buff
[
5
*
i
+
4
]
=
(
float
)
r
.
angle
;
}
res
.
put
(
0
,
0
,
buff
);
}
else
{
res
=
new
Mat
();
}
return
res
;
}
public
static
void
Mat_to_vector_RotatedRect
(
Mat
m
,
List
<
RotatedRect
>
rs
)
{
if
(
rs
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"rs == null"
);
int
count
=
m
.
rows
();
if
(
CvType
.
CV_32FC
(
5
)
!=
m
.
type
()
||
m
.
cols
()
!=
1
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"CvType.CV_32FC5 != m.type() || m.rows()!=1\n"
+
m
);
rs
.
clear
();
float
[]
buff
=
new
float
[
5
*
count
];
m
.
get
(
0
,
0
,
buff
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
rs
.
add
(
new
RotatedRect
(
new
Point
(
buff
[
5
*
i
],
buff
[
5
*
i
+
1
]),
new
Size
(
buff
[
5
*
i
+
2
],
buff
[
5
*
i
+
3
]),
buff
[
5
*
i
+
4
]));
}
}
}
modules/java/test/android_test/src/org/opencv/test/OpenCVTestCase.java
View file @
eaee63d9
...
...
@@ -17,6 +17,7 @@ import org.opencv.core.Mat;
import
org.opencv.core.Point
;
import
org.opencv.core.Point3
;
import
org.opencv.core.Rect
;
import
org.opencv.core.RotatedRect
;
import
org.opencv.core.Scalar
;
import
org.opencv.core.Size
;
import
org.opencv.core.DMatch
;
...
...
@@ -336,6 +337,15 @@ public class OpenCVTestCase extends TestCase {
assertRectEquals
(
list1
.
get
(
i
),
list2
.
get
(
i
));
}
public
static
void
assertListRotatedRectEquals
(
List
<
RotatedRect
>
list1
,
List
<
RotatedRect
>
list2
)
{
if
(
list1
.
size
()
!=
list2
.
size
())
{
throw
new
UnsupportedOperationException
();
}
for
(
int
i
=
0
;
i
<
list1
.
size
();
i
++)
assertRotatedRectEquals
(
list1
.
get
(
i
),
list2
.
get
(
i
));
}
public
static
void
assertRectEquals
(
Rect
expected
,
Rect
actual
)
{
String
msg
=
"expected:<"
+
expected
+
"> but was:<"
+
actual
+
">"
;
assertEquals
(
msg
,
expected
.
x
,
actual
.
x
);
...
...
@@ -344,6 +354,15 @@ public class OpenCVTestCase extends TestCase {
assertEquals
(
msg
,
expected
.
height
,
actual
.
height
);
}
public
static
void
assertRotatedRectEquals
(
RotatedRect
expected
,
RotatedRect
actual
)
{
String
msg
=
"expected:<"
+
expected
+
"> but was:<"
+
actual
+
">"
;
assertEquals
(
msg
,
expected
.
center
.
x
,
actual
.
center
.
x
);
assertEquals
(
msg
,
expected
.
center
.
y
,
actual
.
center
.
y
);
assertEquals
(
msg
,
expected
.
size
.
width
,
actual
.
size
.
width
);
assertEquals
(
msg
,
expected
.
size
.
height
,
actual
.
size
.
height
);
assertEquals
(
msg
,
expected
.
angle
,
actual
.
angle
);
}
public
static
void
assertMatEqual
(
Mat
m1
,
Mat
m2
)
{
compareMats
(
m1
,
m2
,
true
);
}
...
...
modules/java/test/common_test/src/org/opencv/test/utils/ConvertersTest.java
View file @
eaee63d9
...
...
@@ -4,7 +4,9 @@ import org.opencv.core.CvType;
import
org.opencv.core.Mat
;
import
org.opencv.core.Point
;
import
org.opencv.core.Point3
;
import
org.opencv.core.Size
;
import
org.opencv.core.Rect
;
import
org.opencv.core.RotatedRect
;
import
org.opencv.core.DMatch
;
import
org.opencv.core.KeyPoint
;
import
org.opencv.test.OpenCVTestCase
;
...
...
@@ -222,6 +224,19 @@ public class ConvertersTest extends OpenCVTestCase {
assertListRectEquals
(
truth
,
rectangles
);
}
public
void
testMat_to_vector_RotatedRect
()
{
Mat
src
=
new
Mat
(
2
,
1
,
CvType
.
CV_32FC
(
5
));
src
.
put
(
0
,
0
,
2
,
2
,
5
,
2
,
7
,
0
,
6
,
4
,
1
,
3
);
List
<
RotatedRect
>
rectangles
=
new
ArrayList
<
RotatedRect
>();
Converters
.
Mat_to_vector_RotatedRect
(
src
,
rectangles
);
List
<
RotatedRect
>
truth
=
new
ArrayList
<
RotatedRect
>();
truth
.
add
(
new
RotatedRect
(
new
Point
(
2
,
2
),
new
Size
(
5
,
2
),
7
));
truth
.
add
(
new
RotatedRect
(
new
Point
(
0
,
6
),
new
Size
(
4
,
1
),
3
));
assertListRotatedRectEquals
(
truth
,
rectangles
);
}
public
void
testMat_to_vector_uchar
()
{
Mat
src
=
new
Mat
(
3
,
1
,
CvType
.
CV_8UC1
);
src
.
put
(
0
,
0
,
2
,
4
,
3
);
...
...
@@ -465,6 +480,19 @@ public class ConvertersTest extends OpenCVTestCase {
assertMatEqual
(
truth
,
dst
);
}
public
void
testVector_RotatedRect_to_Mat
()
{
List
<
RotatedRect
>
rectangles
=
new
ArrayList
<
RotatedRect
>();
rectangles
.
add
(
new
RotatedRect
(
new
Point
(
2
,
2
),
new
Size
(
5
,
2
),
7
));
rectangles
.
add
(
new
RotatedRect
(
new
Point
(
0
,
0
),
new
Size
(
6
,
4
),
3
));
Mat
dst
=
Converters
.
vector_RotatedRect_to_Mat
(
rectangles
);
Mat
truth
=
new
Mat
(
2
,
1
,
CvType
.
CV_32FC
(
5
));
truth
.
put
(
0
,
0
,
2
,
2
,
5
,
2
,
7
,
0
,
0
,
6
,
4
,
3
);
assertMatEqual
(
truth
,
dst
,
EPS
);
}
public
void
testVector_uchar_to_Mat
()
{
List
<
Byte
>
bytes
=
new
ArrayList
<
Byte
>();
byte
value1
=
1
;
...
...
@@ -498,5 +526,4 @@ public class ConvertersTest extends OpenCVTestCase {
fail
(
"Not yet implemented"
);
}
}
modules/java/test/pure_test/src/org/opencv/test/OpenCVTestCase.java
View file @
eaee63d9
...
...
@@ -20,6 +20,7 @@ import org.opencv.core.Mat;
import
org.opencv.core.Point
;
import
org.opencv.core.Point3
;
import
org.opencv.core.Rect
;
import
org.opencv.core.RotatedRect
;
import
org.opencv.core.Scalar
;
import
org.opencv.core.Size
;
import
org.opencv.core.DMatch
;
...
...
@@ -362,6 +363,15 @@ public class OpenCVTestCase extends TestCase {
assertRectEquals
(
list1
.
get
(
i
),
list2
.
get
(
i
));
}
public
static
void
assertListRotatedRectEquals
(
List
<
RotatedRect
>
list1
,
List
<
RotatedRect
>
list2
)
{
if
(
list1
.
size
()
!=
list2
.
size
())
{
throw
new
UnsupportedOperationException
();
}
for
(
int
i
=
0
;
i
<
list1
.
size
();
i
++)
assertRotatedRectEquals
(
list1
.
get
(
i
),
list2
.
get
(
i
));
}
public
static
void
assertRectEquals
(
Rect
expected
,
Rect
actual
)
{
String
msg
=
"expected:<"
+
expected
+
"> but was:<"
+
actual
+
">"
;
assertEquals
(
msg
,
expected
.
x
,
actual
.
x
);
...
...
@@ -370,6 +380,15 @@ public class OpenCVTestCase extends TestCase {
assertEquals
(
msg
,
expected
.
height
,
actual
.
height
);
}
public
static
void
assertRotatedRectEquals
(
RotatedRect
expected
,
RotatedRect
actual
)
{
String
msg
=
"expected:<"
+
expected
+
"> but was:<"
+
actual
+
">"
;
assertEquals
(
msg
,
expected
.
center
.
x
,
actual
.
center
.
x
);
assertEquals
(
msg
,
expected
.
center
.
y
,
actual
.
center
.
y
);
assertEquals
(
msg
,
expected
.
size
.
width
,
actual
.
size
.
width
);
assertEquals
(
msg
,
expected
.
size
.
height
,
actual
.
size
.
height
);
assertEquals
(
msg
,
expected
.
angle
,
actual
.
angle
);
}
public
static
void
assertMatEqual
(
Mat
m1
,
Mat
m2
)
{
compareMats
(
m1
,
m2
,
true
);
}
...
...
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