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
ea735a04
Commit
ea735a04
authored
Apr 25, 2012
by
Andrey Pavlenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Java API: fixing Mat::put() for non-continuous Mat-s, adding/improving tests
parent
87888984
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
10 deletions
+63
-10
MatTest.java
...s/java/android_test/src/org/opencv/test/core/MatTest.java
+0
-0
ImgprocTest.java
...android_test/src/org/opencv/test/imgproc/ImgprocTest.java
+38
-1
Mat.cpp
modules/java/src/cpp/Mat.cpp
+25
-9
No files found.
modules/java/android_test/src/org/opencv/test/core/MatTest.java
View file @
ea735a04
This diff is collapsed.
Click to expand it.
modules/java/android_test/src/org/opencv/test/imgproc/ImgprocTest.java
View file @
ea735a04
...
@@ -275,7 +275,7 @@ public class ImgprocTest extends OpenCVTestCase {
...
@@ -275,7 +275,7 @@ public class ImgprocTest extends OpenCVTestCase {
assertMatEqual
(
truth
,
hist
,
EPS
);
assertMatEqual
(
truth
,
hist
,
EPS
);
}
}
public
void
testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2
d
()
{
public
void
testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat2
D
()
{
List
<
Mat
>
images
=
Arrays
.
asList
(
gray255
,
gray128
);
List
<
Mat
>
images
=
Arrays
.
asList
(
gray255
,
gray128
);
MatOfInt
channels
=
new
MatOfInt
(
0
,
1
);
MatOfInt
channels
=
new
MatOfInt
(
0
,
1
);
MatOfInt
histSize
=
new
MatOfInt
(
10
,
10
);
MatOfInt
histSize
=
new
MatOfInt
(
10
,
10
);
...
@@ -292,6 +292,43 @@ public class ImgprocTest extends OpenCVTestCase {
...
@@ -292,6 +292,43 @@ public class ImgprocTest extends OpenCVTestCase {
assertMatEqual
(
truth
,
hist
,
EPS
);
assertMatEqual
(
truth
,
hist
,
EPS
);
}
}
public
void
testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloat3D
()
{
List
<
Mat
>
images
=
Arrays
.
asList
(
rgbLena
);
Mat
hist3D
=
new
Mat
();
List
<
Mat
>
histList
=
Arrays
.
asList
(
new
Mat
[]
{
new
Mat
(),
new
Mat
(),
new
Mat
()}
);
MatOfInt
histSize
=
new
MatOfInt
(
10
);
MatOfFloat
ranges
=
new
MatOfFloat
(
0
f
,
256
f
);
for
(
int
i
=
0
;
i
<
rgbLena
.
channels
();
i
++)
{
Imgproc
.
calcHist
(
images
,
new
MatOfInt
(
i
),
new
Mat
(),
histList
.
get
(
i
),
histSize
,
ranges
);
assertEquals
(
10
,
histList
.
get
(
i
).
checkVector
(
1
));
}
Core
.
merge
(
histList
,
hist3D
);
assertEquals
(
CvType
.
CV_32FC3
,
hist3D
.
type
());
Mat
truth
=
new
Mat
(
10
,
1
,
CvType
.
CV_32FC3
);
truth
.
put
(
0
,
0
,
0
,
24870
,
0
,
1863
,
31926
,
1
,
56682
,
37677
,
2260
,
77278
,
44751
,
32436
,
69397
,
41343
,
18526
,
27180
,
40407
,
18658
,
21101
,
15993
,
32042
,
8343
,
18585
,
47786
,
300
,
6567
,
80988
,
0
,
25
,
29447
);
assertMatEqual
(
truth
,
hist3D
,
EPS
);
}
public
void
testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean
()
{
public
void
testCalcHistListOfMatListOfIntegerMatMatListOfIntegerListOfFloatBoolean
()
{
List
<
Mat
>
images
=
Arrays
.
asList
(
gray255
,
gray128
);
List
<
Mat
>
images
=
Arrays
.
asList
(
gray255
,
gray128
);
MatOfInt
channels
=
new
MatOfInt
(
0
,
1
);
MatOfInt
channels
=
new
MatOfInt
(
0
,
1
);
...
...
modules/java/src/cpp/Mat.cpp
View file @
ea735a04
...
@@ -2,11 +2,12 @@
...
@@ -2,11 +2,12 @@
#include "converters.h"
#include "converters.h"
#ifdef DEBUG
#include <android/log.h>
#include <android/log.h>
#define MODULE_LOG_TAG "OpenCV.core.Mat"
#define LOG_TAG "org.opencv.core.Mat"
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, MODULE_LOG_TAG, __VA_ARGS__))
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))
#else //DEBUG
#ifdef DEBUG
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
#else //!DEBUG
#define LOGD(...)
#define LOGD(...)
#endif //DEBUG
#endif //DEBUG
...
@@ -1979,7 +1980,7 @@ template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count,
...
@@ -1979,7 +1980,7 @@ template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count,
if
(
!
buff
)
return
0
;
if
(
!
buff
)
return
0
;
count
*=
sizeof
(
T
);
count
*=
sizeof
(
T
);
int
rest
=
((
m
->
rows
-
row
)
*
m
->
cols
-
col
)
*
m
->
channels
()
*
sizeof
(
T
);
int
rest
=
((
m
->
rows
-
row
)
*
m
->
cols
-
col
)
*
m
->
elemSize
(
);
if
(
count
>
rest
)
count
=
rest
;
if
(
count
>
rest
)
count
=
rest
;
int
res
=
count
;
int
res
=
count
;
...
@@ -1988,14 +1989,14 @@ template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count,
...
@@ -1988,14 +1989,14 @@ template<typename T> static int mat_put(cv::Mat* m, int row, int col, int count,
memcpy
(
m
->
ptr
(
row
,
col
),
buff
,
count
);
memcpy
(
m
->
ptr
(
row
,
col
),
buff
,
count
);
}
else
{
}
else
{
// row by row
// row by row
int
num
=
(
m
->
cols
-
col
-
1
)
*
m
->
channels
()
*
sizeof
(
T
);
// 1st partial row
int
num
=
(
m
->
cols
-
col
)
*
m
->
elemSize
(
);
// 1st partial row
if
(
count
<
num
)
num
=
count
;
if
(
count
<
num
)
num
=
count
;
uchar
*
data
=
m
->
ptr
(
row
++
,
col
);
uchar
*
data
=
m
->
ptr
(
row
++
,
col
);
while
(
count
>
0
){
while
(
count
>
0
){
memcpy
(
data
,
buff
,
num
);
memcpy
(
data
,
buff
,
num
);
count
-=
num
;
count
-=
num
;
buff
+=
num
;
buff
+=
num
;
num
=
m
->
cols
*
m
->
channels
()
*
sizeof
(
T
);
num
=
m
->
cols
*
m
->
elemSize
(
);
if
(
count
<
num
)
num
=
count
;
if
(
count
<
num
)
num
=
count
;
data
=
m
->
ptr
(
row
++
,
0
);
data
=
m
->
ptr
(
row
++
,
0
);
}
}
...
@@ -2197,8 +2198,23 @@ JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump
...
@@ -2197,8 +2198,23 @@ JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump
{
{
cv
::
Mat
*
me
=
(
cv
::
Mat
*
)
self
;
//TODO: check for NULL
cv
::
Mat
*
me
=
(
cv
::
Mat
*
)
self
;
//TODO: check for NULL
std
::
stringstream
s
;
std
::
stringstream
s
;
s
<<
*
me
;
try
{
return
env
->
NewStringUTF
(
s
.
str
().
c_str
());
LOGD
(
"Mat::nDump()"
);
s
<<
*
me
;
return
env
->
NewStringUTF
(
s
.
str
().
c_str
());
}
catch
(
cv
::
Exception
e
)
{
LOGE
(
"Mat::nDump() catched cv::Exception: %s"
,
e
.
what
());
jclass
je
=
env
->
FindClass
(
"org/opencv/core/CvException"
);
if
(
!
je
)
je
=
env
->
FindClass
(
"java/lang/Exception"
);
env
->
ThrowNew
(
je
,
e
.
what
());
return
env
->
NewStringUTF
(
"ERROR"
);
}
catch
(...)
{
LOGE
(
"Mat::nDump() catched unknown exception (...)"
);
jclass
je
=
env
->
FindClass
(
"java/lang/Exception"
);
env
->
ThrowNew
(
je
,
"Unknown exception in JNI code {Mat::nDump()}"
);
return
env
->
NewStringUTF
(
"ERROR"
);
}
}
}
...
...
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