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
92f754c6
Commit
92f754c6
authored
Oct 25, 2018
by
Dmitry Kurtaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add methods to reshape Mat in Java by array of shapes and retreive sizes of each dimension.
parent
9a12aa45
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
0 deletions
+90
-0
core+Mat.java
modules/core/misc/java/src/java/core+Mat.java
+30
-0
MatTest.java
modules/core/misc/java/test/MatTest.java
+13
-0
Mat.cpp
modules/java/generator/src/cpp/Mat.cpp
+47
-0
No files found.
modules/core/misc/java/src/java/core+Mat.java
View file @
92f754c6
...
...
@@ -681,6 +681,18 @@ public class Mat {
return
retVal
;
}
//
// C++: Mat Mat::reshape(int cn, int newndims, const int* newsz)
//
// javadoc: Mat::reshape(cn, newshape)
public
Mat
reshape
(
int
cn
,
int
[]
newshape
)
{
Mat
retVal
=
new
Mat
(
n_reshape_1
(
nativeObj
,
cn
,
newshape
.
length
,
newshape
));
return
retVal
;
}
//
// C++: Mat Mat::row(int y)
//
...
...
@@ -794,6 +806,18 @@ public class Mat {
return
retVal
;
}
//
// C++: int Mat::size(int i)
//
// javadoc: Mat::size(int i)
public
int
size
(
int
i
)
{
int
retVal
=
n_size_i
(
nativeObj
,
i
);
return
retVal
;
}
//
// C++: size_t Mat::step1(int i = 0)
//
...
...
@@ -1271,6 +1295,9 @@ public class Mat {
private
static
native
long
n_reshape
(
long
nativeObj
,
int
cn
);
// C++: Mat Mat::reshape(int cn, int newndims, const int* newsz)
private
static
native
long
n_reshape_1
(
long
nativeObj
,
int
cn
,
int
newndims
,
int
[]
newsz
);
// C++: Mat Mat::row(int y)
private
static
native
long
n_row
(
long
nativeObj
,
int
y
);
...
...
@@ -1294,6 +1321,9 @@ public class Mat {
// C++: Size Mat::size()
private
static
native
double
[]
n_size
(
long
nativeObj
);
// C++: int Mat::size(int i)
private
static
native
int
n_size_i
(
long
nativeObj
,
int
i
);
// C++: size_t Mat::step1(int i = 0)
private
static
native
long
n_step1
(
long
nativeObj
,
int
i
);
...
...
modules/core/misc/java/test/MatTest.java
View file @
92f754c6
...
...
@@ -817,6 +817,19 @@ public class MatTest extends OpenCVTestCase {
assertMatEqual
(
truth
,
dst
);
}
public
void
testReshapeIntIntArray
()
{
Mat
src
=
new
Mat
(
6
,
5
,
CvType
.
CV_8UC3
,
new
Scalar
(
0
));
assertEquals
(
2
,
src
.
dims
());
assertEquals
(
src
.
rows
(),
src
.
size
(
0
));
assertEquals
(
src
.
cols
(),
src
.
size
(
1
));
int
[]
newShape
=
{
1
,
src
.
channels
()
*
src
.
cols
(),
1
,
src
.
rows
()};
dst
=
src
.
reshape
(
1
,
newShape
);
assertEquals
(
newShape
.
length
,
dst
.
dims
());
for
(
int
i
=
0
;
i
<
newShape
.
length
;
++
i
)
assertEquals
(
newShape
[
i
],
dst
.
size
(
i
));
}
public
void
testRow
()
{
Mat
row
=
gray0
.
row
(
0
);
assertEquals
(
1
,
row
.
rows
());
...
...
modules/java/generator/src/cpp/Mat.cpp
View file @
92f754c6
...
...
@@ -528,7 +528,30 @@ JNIEXPORT jint JNICALL Java_org_opencv_core_Mat_n_1cols
return
0
;
}
//
// int Mat::size(int i)
//
JNIEXPORT
jint
JNICALL
Java_org_opencv_core_Mat_n_1size_1i__JI
(
JNIEnv
*
env
,
jclass
,
jlong
self
,
jint
i
);
JNIEXPORT
jint
JNICALL
Java_org_opencv_core_Mat_n_1size_1i__JI
(
JNIEnv
*
env
,
jclass
,
jlong
self
,
jint
i
)
{
static
const
char
method_name
[]
=
"Mat::n_1size_1i__JI()"
;
try
{
LOGD
(
"%s"
,
method_name
);
Mat
*
me
=
(
Mat
*
)
self
;
//TODO: check for NULL
int
_retval_
=
me
->
size
[
i
];
return
_retval_
;
}
catch
(
const
std
::
exception
&
e
)
{
throwJavaException
(
env
,
&
e
,
method_name
);
}
catch
(...)
{
throwJavaException
(
env
,
0
,
method_name
);
}
return
0
;
}
//
// void Mat::convertTo(Mat& m, int rtype, double alpha = 1, double beta = 0)
...
...
@@ -1307,7 +1330,31 @@ JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1reshape__JI
return
0
;
}
//
// Mat Mat::reshape(int cn, int[] newshape)
//
JNIEXPORT
jlong
JNICALL
Java_org_opencv_core_Mat_n_1reshape_11
(
JNIEnv
*
env
,
jclass
,
jlong
self
,
jint
cn
,
jint
newndims
,
jintArray
newshape
);
JNIEXPORT
jlong
JNICALL
Java_org_opencv_core_Mat_n_1reshape_11
(
JNIEnv
*
env
,
jclass
,
jlong
self
,
jint
cn
,
jint
newndims
,
jintArray
newshape
)
{
static
const
char
method_name
[]
=
"Mat::n_1reshape_11"
;
try
{
LOGD
(
"%s"
,
method_name
);
Mat
*
me
=
(
Mat
*
)
self
;
//TODO: check for NULL
int
*
newsz
=
(
int
*
)
env
->
GetPrimitiveArrayCritical
(
newshape
,
0
);
Mat
_retval_
=
me
->
reshape
(
cn
,
newndims
,
newsz
);
return
(
jlong
)
new
Mat
(
_retval_
);
}
catch
(
const
std
::
exception
&
e
)
{
throwJavaException
(
env
,
&
e
,
method_name
);
}
catch
(...)
{
throwJavaException
(
env
,
0
,
method_name
);
}
return
0
;
}
//
// Mat Mat::row(int y)
...
...
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