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
29ce348c
Commit
29ce348c
authored
Aug 24, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12287 from berak:java_matofrotatedrect
parents
b2a4069f
1c20a7f0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
0 deletions
+108
-0
core+MatOfRotatedRect.java
modules/core/misc/java/src/java/core+MatOfRotatedRect.java
+86
-0
RotatedRectTest.java
modules/core/misc/java/test/RotatedRectTest.java
+22
-0
No files found.
modules/core/misc/java/src/java/core+MatOfRotatedRect.java
0 → 100644
View file @
29ce348c
package
org
.
opencv
.
core
;
import
java.util.Arrays
;
import
java.util.List
;
import
org.opencv.core.RotatedRect
;
public
class
MatOfRotatedRect
extends
Mat
{
// 64FC5
private
static
final
int
_depth
=
CvType
.
CV_64F
;
private
static
final
int
_channels
=
5
;
public
MatOfRotatedRect
()
{
super
();
}
protected
MatOfRotatedRect
(
long
addr
)
{
super
(
addr
);
if
(
!
empty
()
&&
checkVector
(
_channels
,
_depth
)
<
0
)
throw
new
IllegalArgumentException
(
"Incompatible Mat"
);
//FIXME: do we need release() here?
}
public
static
MatOfRotatedRect
fromNativeAddr
(
long
addr
)
{
return
new
MatOfRotatedRect
(
addr
);
}
public
MatOfRotatedRect
(
Mat
m
)
{
super
(
m
,
Range
.
all
());
if
(
!
empty
()
&&
checkVector
(
_channels
,
_depth
)
<
0
)
throw
new
IllegalArgumentException
(
"Incompatible Mat"
);
//FIXME: do we need release() here?
}
public
MatOfRotatedRect
(
RotatedRect
...
a
)
{
super
();
fromArray
(
a
);
}
public
void
alloc
(
int
elemNumber
)
{
if
(
elemNumber
>
0
)
super
.
create
(
elemNumber
,
1
,
CvType
.
makeType
(
_depth
,
_channels
));
}
public
void
fromArray
(
RotatedRect
...
a
)
{
if
(
a
==
null
||
a
.
length
==
0
)
return
;
int
num
=
a
.
length
;
alloc
(
num
);
double
buff
[]
=
new
double
[
num
*
_channels
];
for
(
int
i
=
0
;
i
<
num
;
i
++)
{
RotatedRect
r
=
a
[
i
];
buff
[
_channels
*
i
+
0
]
=
(
double
)
r
.
center
.
x
;
buff
[
_channels
*
i
+
1
]
=
(
double
)
r
.
center
.
y
;
buff
[
_channels
*
i
+
2
]
=
(
double
)
r
.
size
.
width
;
buff
[
_channels
*
i
+
3
]
=
(
double
)
r
.
size
.
height
;
buff
[
_channels
*
i
+
4
]
=
(
double
)
r
.
angle
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
RotatedRect
[]
toArray
()
{
int
num
=
(
int
)
total
();
RotatedRect
[]
a
=
new
RotatedRect
[
num
];
if
(
num
==
0
)
return
a
;
double
buff
[]
=
new
double
[
_channels
];
for
(
int
i
=
0
;
i
<
num
;
i
++)
{
get
(
i
,
0
,
buff
);
//TODO: check ret val!
a
[
i
]
=
new
RotatedRect
(
buff
);
}
return
a
;
}
public
void
fromList
(
List
<
RotatedRect
>
lr
)
{
RotatedRect
ap
[]
=
lr
.
toArray
(
new
RotatedRect
[
0
]);
fromArray
(
ap
);
}
public
List
<
RotatedRect
>
toList
()
{
RotatedRect
[]
ar
=
toArray
();
return
Arrays
.
asList
(
ar
);
}
}
modules/core/misc/java/test/RotatedRectTest.java
View file @
29ce348c
package
org
.
opencv
.
test
.
core
;
import
org.opencv.core.CvType
;
import
org.opencv.core.Point
;
import
org.opencv.core.Rect
;
import
org.opencv.core.RotatedRect
;
import
org.opencv.core.MatOfRotatedRect
;
import
org.opencv.core.Size
;
import
org.opencv.test.OpenCVTestCase
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
RotatedRectTest
extends
OpenCVTestCase
{
private
double
angle
;
...
...
@@ -188,4 +193,21 @@ public class RotatedRectTest extends OpenCVTestCase {
assertEquals
(
expected
,
actual
);
}
public
void
testMatOfRotatedRect
()
{
RotatedRect
a
=
new
RotatedRect
(
new
Point
(
1
,
2
),
new
Size
(
3
,
4
),
5.678
);
RotatedRect
b
=
new
RotatedRect
(
new
Point
(
9
,
8
),
new
Size
(
7
,
6
),
5.432
);
MatOfRotatedRect
m
=
new
MatOfRotatedRect
(
a
,
b
,
a
,
b
,
a
,
b
,
a
,
b
);
assertEquals
(
m
.
rows
(),
8
);
assertEquals
(
m
.
cols
(),
1
);
assertEquals
(
m
.
type
(),
CvType
.
CV_64FC
(
5
));
RotatedRect
[]
arr
=
m
.
toArray
();
assertTrue
(
arr
[
2
].
angle
==
5.678
);
assertTrue
(
arr
[
3
].
center
.
x
==
9
);
assertTrue
(
arr
[
3
].
size
.
width
==
7
);
List
<
RotatedRect
>
li
=
m
.
toList
();
assertTrue
(
li
.
size
()
==
8
);
RotatedRect
rr
=
li
.
get
(
7
);
assertTrue
(
rr
.
angle
==
5.432
);
assertTrue
(
rr
.
center
.
y
==
8
);
}
}
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