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
b1ed2771
Commit
b1ed2771
authored
Jul 15, 2011
by
Leonid Beynenson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Java functions, converting vectors to Mats and Mats to vectors.
parent
7c6fc6e1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
121 additions
and
27 deletions
+121
-27
utils.java
modules/java/src/java/utils.java
+121
-27
No files found.
modules/java/src/java/utils.java
View file @
b1ed2771
...
...
@@ -9,12 +9,12 @@ public class utils {
Mat
res
;
int
count
=
(
pts
!=
null
)
?
pts
.
size
()
:
0
;
if
(
count
>
0
){
res
=
new
Mat
(
1
,
count
,
CvType
.
CV_
64F
C2
);
//Point can be saved into double[2]
double
[]
buff
=
new
double
[
count
*
2
];
res
=
new
Mat
(
1
,
count
,
CvType
.
CV_
32S
C2
);
//Point can be saved into double[2]
int
[]
buff
=
new
int
[
count
*
2
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Point
p
=
pts
.
get
(
i
);
buff
[
i
*
2
]
=
p
.
x
;
buff
[
i
*
2
+
1
]
=
p
.
y
;
buff
[
i
*
2
]
=
(
int
)
p
.
x
;
buff
[
i
*
2
+
1
]
=
(
int
)
p
.
y
;
}
res
.
put
(
0
,
0
,
buff
);
}
else
{
...
...
@@ -25,15 +25,15 @@ public class utils {
public
static
void
Mat_to_vector_Point
(
Mat
m
,
List
<
Point
>
pts
)
{
if
(
pts
==
null
)
return
;
throw
new
java
.
lang
.
IllegalArgumentException
()
;
int
cols
=
m
.
cols
();
if
(!
CvType
.
CV_
64FC2
.
equals
(
m
.
type
())
||
m
.
rows
()!=
1
||
cols
%
2
!=
0
)
return
;
if
(!
CvType
.
CV_
32SC2
.
equals
(
m
.
type
())
||
m
.
rows
()!=
1
)
throw
new
java
.
lang
.
IllegalArgumentException
()
;
pts
.
clear
();
double
[]
buff
=
new
double
[
cols
];
int
[]
buff
=
new
int
[
2
*
cols
];
m
.
get
(
0
,
0
,
buff
);
for
(
int
i
=
0
;
i
<
cols
/
2
;
i
++)
{
for
(
int
i
=
0
;
i
<
cols
;
i
++)
{
pts
.
add
(
new
Point
(
buff
[
i
*
2
],
buff
[
i
*
2
+
1
])
);
}
}
...
...
@@ -58,15 +58,15 @@ public class utils {
public
static
void
Mat_to_vector_Mat
(
Mat
m
,
List
<
Mat
>
mats
)
{
if
(
mats
==
null
)
return
;
throw
new
java
.
lang
.
IllegalArgumentException
()
;
int
cols
=
m
.
cols
();
if
(!
CvType
.
CV_32SC2
.
equals
(
m
.
type
())
||
m
.
rows
()!=
1
||
cols
%
2
!=
0
)
return
;
if
(!
CvType
.
CV_32SC2
.
equals
(
m
.
type
())
||
m
.
rows
()!=
1
)
throw
new
java
.
lang
.
IllegalArgumentException
()
;
mats
.
clear
();
int
[]
buff
=
new
int
[
cols
];
int
[]
buff
=
new
int
[
cols
*
2
];
m
.
get
(
0
,
0
,
buff
);
for
(
int
i
=
0
;
i
<
cols
/
2
;
i
++)
{
for
(
int
i
=
0
;
i
<
cols
;
i
++)
{
long
addr
=
(((
long
)
buff
[
i
*
2
])<<
32
)
|
((
long
)
buff
[
i
*
2
+
1
]);
mats
.
add
(
new
Mat
(
addr
)
);
}
...
...
@@ -77,42 +77,136 @@ public class utils {
}
public
static
Mat
vector_float_to_Mat
(
List
<
Float
>
fs
)
{
// TODO Auto-generated method stub
return
null
;
Mat
res
;
int
count
=
(
fs
!=
null
)
?
fs
.
size
()
:
0
;
if
(
count
>
0
){
res
=
new
Mat
(
1
,
count
,
CvType
.
CV_32FC1
);
//Point can be saved into double[2]
float
[]
buff
=
new
float
[
count
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
float
f
=
fs
.
get
(
i
);
buff
[
i
]
=
f
;
}
res
.
put
(
0
,
0
,
buff
);
}
else
{
res
=
new
Mat
();
}
return
res
;
}
public
static
void
Mat_to_vector_float
(
Mat
m
,
List
<
Float
>
fs
)
{
// TODO Auto-generated method stub
if
(
fs
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
();
int
cols
=
m
.
cols
();
if
(!
CvType
.
CV_32FC1
.
equals
(
m
.
type
())
||
m
.
rows
()!=
1
)
throw
new
java
.
lang
.
IllegalArgumentException
();
fs
.
clear
();
float
[]
buff
=
new
float
[
cols
];
m
.
get
(
0
,
0
,
buff
);
for
(
int
i
=
0
;
i
<
cols
;
i
++)
{
fs
.
add
(
new
Float
(
buff
[
i
])
);
}
}
public
static
Mat
vector_uchar_to_Mat
(
List
<
Byte
>
bs
)
{
// TODO Auto-generated method stub
return
null
;
Mat
res
;
int
count
=
(
bs
!=
null
)
?
bs
.
size
()
:
0
;
if
(
count
>
0
){
res
=
new
Mat
(
1
,
count
,
CvType
.
CV_8UC1
);
//Point can be saved into double[2]
byte
[]
buff
=
new
byte
[
count
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
byte
b
=
bs
.
get
(
i
);
buff
[
i
]
=
b
;
}
res
.
put
(
0
,
0
,
buff
);
}
else
{
res
=
new
Mat
();
}
return
res
;
}
public
static
Mat
vector_int_to_Mat
(
List
<
Integer
>
is
)
{
// TODO Auto-generated method stub
return
null
;
Mat
res
;
int
count
=
(
is
!=
null
)
?
is
.
size
()
:
0
;
if
(
count
>
0
){
res
=
new
Mat
(
1
,
count
,
CvType
.
CV_32SC1
);
//Point can be saved into double[2]
int
[]
buff
=
new
int
[
count
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
int
v
=
is
.
get
(
i
);
buff
[
i
]
=
v
;
}
res
.
put
(
0
,
0
,
buff
);
}
else
{
res
=
new
Mat
();
}
return
res
;
}
public
static
void
Mat_to_vector_int
(
Mat
m
,
List
<
Integer
>
is
)
{
// TODO Auto-generated method stub
if
(
is
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
();
int
cols
=
m
.
cols
();
if
(!
CvType
.
CV_32SC1
.
equals
(
m
.
type
())
||
m
.
rows
()!=
1
)
throw
new
java
.
lang
.
IllegalArgumentException
();
is
.
clear
();
int
[]
buff
=
new
int
[
cols
];
m
.
get
(
0
,
0
,
buff
);
for
(
int
i
=
0
;
i
<
cols
;
i
++)
{
is
.
add
(
new
Integer
(
buff
[
i
])
);
}
}
public
static
Mat
vector_Rect_to_Mat
(
List
<
Rect
>
rs
)
{
// TODO Auto-generated method stub
return
null
;
Mat
res
;
int
count
=
(
rs
!=
null
)
?
rs
.
size
()
:
0
;
if
(
count
>
0
){
res
=
new
Mat
(
1
,
count
,
CvType
.
CV_32SC4
);
//Point can be saved into double[2]
int
[]
buff
=
new
int
[
4
*
count
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Rect
r
=
rs
.
get
(
i
);
buff
[
4
*
i
]
=
r
.
x
;
buff
[
4
*
i
+
1
]
=
r
.
y
;
buff
[
4
*
i
+
2
]
=
r
.
width
;
buff
[
4
*
i
+
3
]
=
r
.
height
;
}
res
.
put
(
0
,
0
,
buff
);
}
else
{
res
=
new
Mat
();
}
return
res
;
}
public
static
void
Mat_to_vector_Rect
(
Mat
m
,
List
<
Rect
>
rs
)
{
// TODO Auto-generated method stub
if
(
rs
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
();
int
cols
=
m
.
cols
();
if
(!
CvType
.
CV_32SC4
.
equals
(
m
.
type
())
||
m
.
rows
()!=
1
)
throw
new
java
.
lang
.
IllegalArgumentException
();
rs
.
clear
();
int
[]
buff
=
new
int
[
4
*
cols
];
m
.
get
(
0
,
0
,
buff
);
for
(
int
i
=
0
;
i
<
cols
;
i
++)
{
rs
.
add
(
new
Rect
(
buff
[
4
*
i
],
buff
[
4
*
i
+
1
],
buff
[
4
*
i
+
2
],
buff
[
4
*
i
+
3
])
);
}
}
public
static
Mat
vector_double_to_Mat
(
List
<
Double
>
ds
)
{
// TODO Auto-generated method stub
return
null
;
Mat
res
;
int
count
=
(
ds
!=
null
)
?
ds
.
size
()
:
0
;
if
(
count
>
0
){
res
=
new
Mat
(
1
,
count
,
CvType
.
CV_64FC1
);
//Point can be saved into double[2]
double
[]
buff
=
new
double
[
count
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
double
v
=
ds
.
get
(
i
);
buff
[
i
]
=
v
;
}
res
.
put
(
0
,
0
,
buff
);
}
else
{
res
=
new
Mat
();
}
return
res
;
}
}
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