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
78d92584
Commit
78d92584
authored
Apr 04, 2012
by
Andrey Pavlenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Java API: changing C++ vector<T> handling;
Java tests fixes are expected shortly
parent
9ac0d432
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
689 additions
and
46 deletions
+689
-46
gen_java.py
modules/java/gen_java.py
+0
-0
converters.cpp
modules/java/src/cpp/converters.cpp
+23
-10
converters.h
modules/java/src/cpp/converters.h
+1
-0
core+CvVector.java
modules/java/src/java/core+CvVector.java
+35
-0
core+CvVectorByte.java
modules/java/src/java/core+CvVectorByte.java
+42
-0
core+CvVectorDMatch.java
modules/java/src/java/core+CvVectorDMatch.java
+49
-0
core+CvVectorDouble.java
modules/java/src/java/core+CvVectorDouble.java
+37
-0
core+CvVectorFloat.java
modules/java/src/java/core+CvVectorFloat.java
+41
-0
core+CvVectorFloat4.java
modules/java/src/java/core+CvVectorFloat4.java
+22
-0
core+CvVectorFloat6.java
modules/java/src/java/core+CvVectorFloat6.java
+21
-0
core+CvVectorInt.java
modules/java/src/java/core+CvVectorInt.java
+38
-0
core+CvVectorKeyPoint.java
modules/java/src/java/core+CvVectorKeyPoint.java
+53
-0
core+CvVectorPoint.java
modules/java/src/java/core+CvVectorPoint.java
+45
-0
core+CvVectorPoint2f.java
modules/java/src/java/core+CvVectorPoint2f.java
+45
-0
core+CvVectorPoint3.java
modules/java/src/java/core+CvVectorPoint3.java
+46
-0
core+CvVectorPoint3f.java
modules/java/src/java/core+CvVectorPoint3f.java
+46
-0
core+CvVectorRect.java
modules/java/src/java/core+CvVectorRect.java
+48
-0
utils+Converters.java
modules/java/src/java/utils+Converters.java
+46
-28
FdView.java
...roid/face-detection/src/org/opencv/samples/fd/FdView.java
+4
-4
Sample2View.java
...vcamera/src/org/opencv/samples/tutorial2/Sample2View.java
+47
-4
No files found.
modules/java/gen_java.py
View file @
78d92584
This diff is collapsed.
Click to expand it.
modules/java/src/cpp/converters.cpp
View file @
78d92584
...
...
@@ -185,11 +185,11 @@ void vector_Point3d_to_Mat(vector<Point3d>& v_point, Mat& mat)
void
Mat_to_vector_KeyPoint
(
Mat
&
mat
,
vector
<
KeyPoint
>&
v_kp
)
{
v_kp
.
clear
();
CHECK_MAT
(
mat
.
type
()
==
CV_
64
FC
(
7
)
&&
mat
.
cols
==
1
);
CHECK_MAT
(
mat
.
type
()
==
CV_
32
FC
(
7
)
&&
mat
.
cols
==
1
);
for
(
int
i
=
0
;
i
<
mat
.
rows
;
i
++
)
{
Vec
<
double
,
7
>
v
=
mat
.
at
<
Vec
<
double
,
7
>
>
(
i
,
0
);
KeyPoint
kp
(
(
float
)
v
[
0
],
(
float
)
v
[
1
],
(
float
)
v
[
2
],
(
float
)
v
[
3
],
(
float
)
v
[
4
],
(
int
)
v
[
5
],
(
int
)
v
[
6
]);
Vec
<
float
,
7
>
v
=
mat
.
at
<
Vec
<
float
,
7
>
>
(
i
,
0
);
KeyPoint
kp
(
v
[
0
],
v
[
1
],
v
[
2
],
v
[
3
],
v
[
4
],
(
int
)
v
[
5
],
(
int
)
v
[
6
]);
v_kp
.
push_back
(
kp
);
}
return
;
...
...
@@ -199,11 +199,11 @@ void Mat_to_vector_KeyPoint(Mat& mat, vector<KeyPoint>& v_kp)
void
vector_KeyPoint_to_Mat
(
vector
<
KeyPoint
>&
v_kp
,
Mat
&
mat
)
{
int
count
=
v_kp
.
size
();
mat
.
create
(
count
,
1
,
CV_
64
FC
(
7
));
mat
.
create
(
count
,
1
,
CV_
32
FC
(
7
));
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
KeyPoint
kp
=
v_kp
[
i
];
mat
.
at
<
Vec
<
double
,
7
>
>
(
i
,
0
)
=
Vec
<
double
,
7
>
(
kp
.
pt
.
x
,
kp
.
pt
.
y
,
kp
.
size
,
kp
.
angle
,
kp
.
response
,
kp
.
octave
,
kp
.
class_id
);
mat
.
at
<
Vec
<
float
,
7
>
>
(
i
,
0
)
=
Vec
<
float
,
7
>
(
kp
.
pt
.
x
,
kp
.
pt
.
y
,
kp
.
size
,
kp
.
angle
,
kp
.
response
,
kp
.
octave
,
kp
.
class_id
);
}
}
#endif
...
...
@@ -245,11 +245,11 @@ void vector_Mat_to_Mat(std::vector<cv::Mat>& v_mat, cv::Mat& mat)
void
Mat_to_vector_DMatch
(
Mat
&
mat
,
vector
<
DMatch
>&
v_dm
)
{
v_dm
.
clear
();
CHECK_MAT
(
mat
.
type
()
==
CV_
64
FC4
&&
mat
.
cols
==
1
);
CHECK_MAT
(
mat
.
type
()
==
CV_
32
FC4
&&
mat
.
cols
==
1
);
for
(
int
i
=
0
;
i
<
mat
.
rows
;
i
++
)
{
Vec
<
double
,
4
>
v
=
mat
.
at
<
Vec
<
double
,
4
>
>
(
i
,
0
);
DMatch
dm
((
int
)
v
[
0
],
(
int
)
v
[
1
],
(
int
)
v
[
2
],
(
float
)
v
[
3
]);
Vec
<
float
,
4
>
v
=
mat
.
at
<
Vec
<
float
,
4
>
>
(
i
,
0
);
DMatch
dm
((
int
)
v
[
0
],
(
int
)
v
[
1
],
(
int
)
v
[
2
],
v
[
3
]);
v_dm
.
push_back
(
dm
);
}
return
;
...
...
@@ -259,11 +259,11 @@ void Mat_to_vector_DMatch(Mat& mat, vector<DMatch>& v_dm)
void
vector_DMatch_to_Mat
(
vector
<
DMatch
>&
v_dm
,
Mat
&
mat
)
{
int
count
=
v_dm
.
size
();
mat
.
create
(
count
,
1
,
CV_
64
FC4
);
mat
.
create
(
count
,
1
,
CV_
32
FC4
);
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
DMatch
dm
=
v_dm
[
i
];
mat
.
at
<
Vec
<
double
,
4
>
>
(
i
,
0
)
=
Vec
<
double
,
4
>
(
dm
.
queryIdx
,
dm
.
trainIdx
,
dm
.
imgIdx
,
dm
.
distance
);
mat
.
at
<
Vec
<
float
,
4
>
>
(
i
,
0
)
=
Vec
<
float
,
4
>
(
dm
.
queryIdx
,
dm
.
trainIdx
,
dm
.
imgIdx
,
dm
.
distance
);
}
}
#endif
...
...
@@ -374,6 +374,19 @@ void vector_vector_Point2f_to_Mat(vector< vector< Point2f > >& vv_pt, Mat& mat)
vector_Mat_to_Mat
(
vm
,
mat
);
}
void
vector_vector_Point_to_Mat
(
vector
<
vector
<
Point
>
>&
vv_pt
,
Mat
&
mat
)
{
vector
<
Mat
>
vm
;
vm
.
reserve
(
vv_pt
.
size
()
);
for
(
size_t
i
=
0
;
i
<
vv_pt
.
size
();
i
++
)
{
Mat
m
;
vector_Point_to_Mat
(
vv_pt
[
i
],
m
);
vm
.
push_back
(
m
);
}
vector_Mat_to_Mat
(
vm
,
mat
);
}
void
vector_Vec4f_to_Mat
(
vector
<
Vec4f
>&
v_vec
,
Mat
&
mat
)
{
mat
=
Mat
(
v_vec
,
true
);
...
...
modules/java/src/cpp/converters.h
View file @
78d92584
...
...
@@ -64,4 +64,5 @@ void vector_vector_char_to_Mat(std::vector< std::vector< char > >& vv_ch, cv::Ma
void
Mat_to_vector_vector_Point
(
cv
::
Mat
&
mat
,
std
::
vector
<
std
::
vector
<
cv
::
Point
>
>&
vv_pt
);
void
vector_vector_Point2f_to_Mat
(
std
::
vector
<
std
::
vector
<
cv
::
Point2f
>
>&
vv_pt
,
cv
::
Mat
&
mat
);
void
vector_vector_Point_to_Mat
(
std
::
vector
<
std
::
vector
<
cv
::
Point
>
>&
vv_pt
,
cv
::
Mat
&
mat
);
modules/java/src/java/core+CvVector.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVector
extends
Mat
{
protected
int
depth
;
protected
int
channels
;
protected
CvVector
(
int
d
,
int
ch
)
{
super
();
depth
=
d
;
channels
=
ch
;
}
protected
CvVector
(
int
d
,
int
ch
,
long
addr
)
{
super
(
addr
);
depth
=
d
;
channels
=
ch
;
if
(
!
empty
()
&&
checkVector
(
channels
,
depth
)
<
0
)
throw
new
IllegalArgumentException
(
"Incomatible Mat"
);
//FIXME: do we need release() here?
}
protected
CvVector
(
int
d
,
int
ch
,
Mat
m
)
{
super
(
m
,
Range
.
all
());
depth
=
d
;
channels
=
ch
;
if
(
!
empty
()
&&
checkVector
(
channels
,
depth
)
<
0
)
throw
new
IllegalArgumentException
(
"Incomatible Mat"
);
//FIXME: do we need release() here?
}
protected
void
create
(
int
cnt
)
{
if
(
cnt
>
0
)
super
.
create
(
cnt
,
1
,
CvType
.
makeType
(
depth
,
channels
));
}
}
modules/java/src/java/core+CvVectorByte.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorByte
extends
CvVector
{
private
static
final
int
_d
=
CvType
.
CV_8U
;
public
CvVectorByte
(
int
ch
)
{
super
(
_d
,
ch
);
}
public
CvVectorByte
(
int
ch
,
long
addr
)
{
super
(
_d
,
ch
,
addr
);
}
public
CvVectorByte
(
long
addr
)
{
super
(
_d
,
1
,
addr
);
}
public
CvVectorByte
(
int
ch
,
Mat
m
)
{
super
(
_d
,
ch
,
m
);
}
public
CvVectorByte
(
int
ch
,
byte
[]
a
)
{
super
(
_d
,
ch
);
if
(
a
!=
null
)
{
int
cnt
=
a
.
length
/
ch
;
create
(
cnt
);
put
(
0
,
0
,
a
);
}
}
public
byte
[]
toArray
(
byte
[]
a
)
{
int
cnt
=
(
int
)
total
()
*
channels
;
if
(
cnt
==
0
)
return
new
byte
[
0
];
//null;
byte
[]
res
=
a
;
if
(
res
==
null
||
res
.
length
<
cnt
)
res
=
new
byte
[
cnt
];
get
(
0
,
0
,
res
);
//TODO: check ret val!
return
res
;
}
}
modules/java/src/java/core+CvVectorDMatch.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
import
org.opencv.features2d.DMatch
;
public
class
CvVectorDMatch
extends
CvVectorFloat
{
private
static
final
int
_ch
=
4
;
//xxxC4
public
CvVectorDMatch
()
{
super
(
_ch
);
}
public
CvVectorDMatch
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorDMatch
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorDMatch
(
DMatch
[]
a
)
{
super
(
_ch
);
if
(
a
==
null
)
return
;
int
cnt
=
a
.
length
;
create
(
cnt
);
float
buff
[]
=
new
float
[
_ch
*
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
DMatch
m
=
a
[
i
];
buff
[
_ch
*
i
+
0
]
=
m
.
queryIdx
;
buff
[
_ch
*
i
+
1
]
=
m
.
trainIdx
;
buff
[
_ch
*
i
+
2
]
=
m
.
imgIdx
;
buff
[
_ch
*
i
+
3
]
=
m
.
distance
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
DMatch
[]
toArray
(
DMatch
[]
a
)
{
float
buff
[]
=
super
.
toArray
(
null
);
if
(
buff
.
length
==
0
)
return
new
DMatch
[
0
];
//null;
int
cnt
=
buff
.
length
/
_ch
;
DMatch
[]
res
=
a
;
if
(
a
==
null
||
a
.
length
<
cnt
)
res
=
new
DMatch
[
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
res
[
i
]
=
new
DMatch
((
int
)
buff
[
_ch
*
i
+
0
],
(
int
)
buff
[
_ch
*
i
+
1
],
(
int
)
buff
[
_ch
*
i
+
2
],
buff
[
_ch
*
i
+
3
]);
return
res
;
}
}
modules/java/src/java/core+CvVectorDouble.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorDouble
extends
CvVector
{
private
static
final
int
_d
=
CvType
.
CV_64F
;
public
CvVectorDouble
(
int
ch
)
{
super
(
_d
,
ch
);
}
public
CvVectorDouble
(
int
ch
,
long
addr
)
{
super
(
_d
,
ch
,
addr
);
}
public
CvVectorDouble
(
int
ch
,
Mat
m
)
{
super
(
_d
,
ch
,
m
);
}
public
CvVectorDouble
(
int
ch
,
double
[]
a
)
{
super
(
_d
,
ch
);
if
(
a
!=
null
)
{
int
cnt
=
a
.
length
/
ch
;
create
(
cnt
);
put
(
0
,
0
,
a
);
}
}
public
double
[]
toArray
(
double
[]
a
)
{
int
cnt
=
(
int
)
total
()
*
channels
;
if
(
cnt
==
0
)
return
new
double
[
0
];
//null;
double
[]
res
=
a
;
if
(
res
==
null
||
res
.
length
<
cnt
)
res
=
new
double
[
cnt
];
get
(
0
,
0
,
res
);
//TODO: check ret val!
return
res
;
}
}
modules/java/src/java/core+CvVectorFloat.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorFloat
extends
CvVector
{
private
static
final
int
_d
=
CvType
.
CV_32F
;
public
CvVectorFloat
(
int
ch
)
{
super
(
_d
,
ch
);
}
public
CvVectorFloat
(
int
ch
,
long
addr
)
{
super
(
_d
,
ch
,
addr
);
}
public
CvVectorFloat
(
long
addr
)
{
super
(
_d
,
1
,
addr
);
}
public
CvVectorFloat
(
int
ch
,
Mat
m
)
{
super
(
_d
,
ch
,
m
);
}
public
CvVectorFloat
(
int
ch
,
float
[]
a
)
{
super
(
_d
,
ch
);
if
(
a
!=
null
)
{
int
cnt
=
a
.
length
/
ch
;
create
(
cnt
);
put
(
0
,
0
,
a
);
}
}
public
float
[]
toArray
(
float
[]
a
)
{
int
cnt
=
(
int
)
total
()
*
channels
;
if
(
cnt
==
0
)
return
new
float
[
0
];
//null;
float
[]
res
=
a
;
if
(
res
==
null
||
res
.
length
<
cnt
)
res
=
new
float
[
cnt
];
get
(
0
,
0
,
res
);
//TODO: check ret val!
return
res
;
}
}
modules/java/src/java/core+CvVectorFloat4.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorFloat4
extends
CvVectorFloat
{
private
static
final
int
_ch
=
4
;
//xxxC4
public
CvVectorFloat4
()
{
super
(
_ch
);
}
public
CvVectorFloat4
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorFloat4
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorFloat4
(
float
[]
a
)
{
super
(
_ch
,
a
);
}
}
modules/java/src/java/core+CvVectorFloat6.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorFloat6
extends
CvVectorFloat
{
private
static
final
int
_ch
=
6
;
//xxxC6
public
CvVectorFloat6
()
{
super
(
_ch
);
}
public
CvVectorFloat6
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorFloat6
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorFloat6
(
float
[]
a
)
{
super
(
_ch
,
a
);
}
}
modules/java/src/java/core+CvVectorInt.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorInt
extends
CvVector
{
private
static
final
int
_d
=
CvType
.
CV_32S
;
public
CvVectorInt
(
int
ch
)
{
super
(
_d
,
ch
);
}
public
CvVectorInt
(
int
ch
,
long
addr
)
{
super
(
_d
,
ch
,
addr
);
}
public
CvVectorInt
(
int
ch
,
Mat
m
)
{
super
(
_d
,
ch
,
m
);
}
public
CvVectorInt
(
int
ch
,
int
[]
a
)
{
super
(
_d
,
ch
);
if
(
a
!=
null
)
{
int
cnt
=
a
.
length
/
ch
;
create
(
cnt
);
put
(
0
,
0
,
a
);
}
}
public
int
[]
toArray
(
int
[]
a
)
{
int
cnt
=
(
int
)
total
()
*
channels
;
if
(
cnt
==
0
)
return
new
int
[
0
];
//null;
int
[]
res
=
a
;
if
(
res
==
null
||
res
.
length
<
cnt
)
res
=
new
int
[
cnt
];
get
(
0
,
0
,
res
);
//TODO: check ret val!
return
res
;
}
}
modules/java/src/java/core+CvVectorKeyPoint.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
import
org.opencv.features2d.KeyPoint
;
public
class
CvVectorKeyPoint
extends
CvVectorFloat
{
private
static
final
int
_ch
=
7
;
//xxxC7
public
CvVectorKeyPoint
()
{
super
(
_ch
);
}
public
CvVectorKeyPoint
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorKeyPoint
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorKeyPoint
(
KeyPoint
[]
a
)
{
super
(
_ch
);
if
(
a
==
null
)
return
;
int
cnt
=
a
.
length
;
create
(
cnt
);
float
buff
[]
=
new
float
[
_ch
*
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
KeyPoint
kp
=
a
[
i
];
buff
[
_ch
*
i
+
0
]
=
(
float
)
kp
.
pt
.
x
;
buff
[
_ch
*
i
+
1
]
=
(
float
)
kp
.
pt
.
y
;
buff
[
_ch
*
i
+
2
]
=
kp
.
size
;
buff
[
_ch
*
i
+
3
]
=
kp
.
angle
;
buff
[
_ch
*
i
+
4
]
=
kp
.
response
;
buff
[
_ch
*
i
+
5
]
=
kp
.
octave
;
buff
[
_ch
*
i
+
6
]
=
kp
.
class_id
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
KeyPoint
[]
toArray
(
KeyPoint
[]
a
)
{
float
buff
[]
=
super
.
toArray
(
null
);
if
(
buff
.
length
==
0
)
return
new
KeyPoint
[
0
];
//null;
int
cnt
=
buff
.
length
/
_ch
;
KeyPoint
[]
res
=
a
;
if
(
a
==
null
||
a
.
length
<
cnt
)
res
=
new
KeyPoint
[
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
res
[
i
]
=
new
KeyPoint
(
buff
[
_ch
*
i
+
0
],
buff
[
_ch
*
i
+
1
],
buff
[
_ch
*
i
+
2
],
buff
[
_ch
*
i
+
3
],
buff
[
_ch
*
i
+
4
],
(
int
)
buff
[
_ch
*
i
+
5
],
(
int
)
buff
[
_ch
*
i
+
6
]
);
return
res
;
}
}
modules/java/src/java/core+CvVectorPoint.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorPoint
extends
CvVectorInt
{
private
static
final
int
_ch
=
2
;
//xxxC2
public
CvVectorPoint
()
{
super
(
_ch
);
}
public
CvVectorPoint
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorPoint
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorPoint
(
Point
[]
a
)
{
super
(
_ch
);
if
(
a
==
null
)
return
;
int
cnt
=
a
.
length
;
create
(
cnt
);
int
buff
[]
=
new
int
[
_ch
*
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
Point
p
=
a
[
i
];
buff
[
_ch
*
i
+
0
]
=
(
int
)
p
.
x
;
buff
[
_ch
*
i
+
1
]
=
(
int
)
p
.
y
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
Point
[]
toArray
(
Point
[]
a
)
{
int
buff
[]
=
super
.
toArray
(
null
);
if
(
buff
.
length
==
0
)
return
new
Point
[
0
];
//null;
int
cnt
=
buff
.
length
/
_ch
;
Point
[]
res
=
a
;
if
(
a
==
null
||
a
.
length
<
cnt
)
res
=
new
Point
[
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
res
[
i
]
=
new
Point
(
buff
[
i
*
_ch
],
buff
[
i
*
_ch
+
1
]);
return
res
;
}
}
modules/java/src/java/core+CvVectorPoint2f.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorPoint2f
extends
CvVectorFloat
{
private
static
final
int
_ch
=
2
;
//xxxC2
public
CvVectorPoint2f
()
{
super
(
_ch
);
}
public
CvVectorPoint2f
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorPoint2f
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorPoint2f
(
Point
[]
a
)
{
super
(
_ch
);
if
(
a
==
null
)
return
;
int
cnt
=
a
.
length
;
create
(
cnt
);
float
buff
[]
=
new
float
[
_ch
*
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
Point
p
=
a
[
i
];
buff
[
_ch
*
i
+
0
]
=
(
float
)
p
.
x
;
buff
[
_ch
*
i
+
1
]
=
(
float
)
p
.
y
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
Point
[]
toArray
(
Point
[]
a
)
{
float
buff
[]
=
super
.
toArray
(
null
);
if
(
buff
.
length
==
0
)
return
new
Point
[
0
];
//null;
int
cnt
=
buff
.
length
/
_ch
;
Point
[]
res
=
a
;
if
(
a
==
null
||
a
.
length
<
cnt
)
res
=
new
Point
[
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
res
[
i
]
=
new
Point
(
buff
[
i
*
_ch
],
buff
[
i
*
_ch
+
1
]);
return
res
;
}
}
modules/java/src/java/core+CvVectorPoint3.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorPoint3
extends
CvVectorInt
{
private
static
final
int
_ch
=
3
;
//xxxC2
public
CvVectorPoint3
()
{
super
(
_ch
);
}
public
CvVectorPoint3
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorPoint3
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorPoint3
(
Point3
[]
a
)
{
super
(
_ch
);
if
(
a
==
null
)
return
;
int
cnt
=
a
.
length
;
create
(
cnt
);
int
buff
[]
=
new
int
[
_ch
*
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
Point3
p
=
a
[
i
];
buff
[
_ch
*
i
]
=
(
int
)
p
.
x
;
buff
[
_ch
*
i
+
1
]
=
(
int
)
p
.
y
;
buff
[
_ch
*
i
+
2
]
=
(
int
)
p
.
z
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
Point3
[]
toArray
(
Point3
[]
a
)
{
int
buff
[]
=
super
.
toArray
(
null
);
if
(
buff
.
length
==
0
)
return
new
Point3
[
0
];
//null;
int
cnt
=
buff
.
length
/
_ch
;
Point3
[]
res
=
a
;
if
(
a
==
null
||
a
.
length
<
cnt
)
res
=
new
Point3
[
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
res
[
i
]
=
new
Point3
(
buff
[
i
*
_ch
],
buff
[
i
*
_ch
+
1
],
buff
[
i
*
_ch
+
2
]);
return
res
;
}
}
modules/java/src/java/core+CvVectorPoint3f.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorPoint3f
extends
CvVectorFloat
{
private
static
final
int
_ch
=
3
;
//xxxC2
public
CvVectorPoint3f
()
{
super
(
_ch
);
}
public
CvVectorPoint3f
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorPoint3f
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorPoint3f
(
Point3
[]
a
)
{
super
(
_ch
);
if
(
a
==
null
)
return
;
int
cnt
=
a
.
length
;
create
(
cnt
);
float
buff
[]
=
new
float
[
_ch
*
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
Point3
p
=
a
[
i
];
buff
[
_ch
*
i
]
=
(
float
)
p
.
x
;
buff
[
_ch
*
i
+
1
]
=
(
float
)
p
.
y
;
buff
[
_ch
*
i
+
2
]
=
(
float
)
p
.
z
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
Point3
[]
toArray
(
Point3
[]
a
)
{
float
buff
[]
=
super
.
toArray
(
null
);
if
(
buff
.
length
==
0
)
return
new
Point3
[
0
];
//null;
int
cnt
=
buff
.
length
/
_ch
;
Point3
[]
res
=
a
;
if
(
a
==
null
||
a
.
length
<
cnt
)
res
=
new
Point3
[
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
res
[
i
]
=
new
Point3
(
buff
[
i
*
_ch
],
buff
[
i
*
_ch
+
1
],
buff
[
i
*
_ch
+
2
]);
return
res
;
}
}
modules/java/src/java/core+CvVectorRect.java
0 → 100644
View file @
78d92584
package
org
.
opencv
.
core
;
public
class
CvVectorRect
extends
CvVectorInt
{
private
static
final
int
_ch
=
4
;
//xxxC4
public
CvVectorRect
()
{
super
(
_ch
);
}
public
CvVectorRect
(
long
addr
)
{
super
(
_ch
,
addr
);
}
public
CvVectorRect
(
Mat
m
)
{
super
(
_ch
,
m
);
}
public
CvVectorRect
(
Rect
[]
a
)
{
super
(
_ch
);
if
(
a
==
null
)
return
;
int
cnt
=
a
.
length
;
create
(
cnt
);
int
buff
[]
=
new
int
[
_ch
*
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
{
Rect
r
=
a
[
i
];
buff
[
_ch
*
i
]
=
r
.
x
;
buff
[
_ch
*
i
+
1
]
=
r
.
y
;
buff
[
_ch
*
i
+
2
]
=
r
.
width
;
buff
[
_ch
*
i
+
3
]
=
r
.
height
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
Rect
[]
toArray
(
Rect
[]
a
)
{
int
buff
[]
=
super
.
toArray
(
null
);
if
(
buff
.
length
==
0
)
return
new
Rect
[
0
];
//null;
int
cnt
=
buff
.
length
/
_ch
;
Rect
[]
res
=
a
;
if
(
a
==
null
||
a
.
length
<
cnt
)
res
=
new
Rect
[
cnt
];
for
(
int
i
=
0
;
i
<
cnt
;
i
++)
res
[
i
]
=
new
Rect
(
buff
[
i
*
_ch
],
buff
[
i
*
_ch
+
1
],
buff
[
i
*
_ch
+
2
],
buff
[
i
*
_ch
+
3
]);
return
res
;
}
}
modules/java/src/java/utils+Converters.java
View file @
78d92584
...
...
@@ -3,11 +3,16 @@ package org.opencv.utils;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.opencv.core.Mat
;
import
org.opencv.core.CvType
;
import
org.opencv.core.CvVectorPoint2f
;
import
org.opencv.core.Mat
;
import
org.opencv.core.Point
;
import
org.opencv.core.Point3
;
import
org.opencv.core.Rect
;
import
org.opencv.core.CvVectorByte
;
import
org.opencv.core.CvVectorDMatch
;
import
org.opencv.core.CvVectorKeyPoint
;
import
org.opencv.core.CvVectorPoint
;
import
org.opencv.features2d.DMatch
;
import
org.opencv.features2d.KeyPoint
;
...
...
@@ -468,14 +473,14 @@ public class Converters {
(
float
)
buff
[
7
*
i
+
4
],
(
int
)
buff
[
7
*
i
+
5
],
(
int
)
buff
[
7
*
i
+
6
]));
}
}
// vector_vector_Point
public
static
Mat
vector_vector_Point_to_Mat
(
List
<
List
<
Point
>
>
pts
,
List
<
Mat
>
mats
)
{
public
static
Mat
vector_vector_Point_to_Mat
(
List
<
CvVectorPoint
>
pts
,
List
<
Mat
>
mats
)
{
Mat
res
;
int
lCount
=
(
pts
!=
null
)
?
pts
.
size
()
:
0
;
if
(
lCount
>
0
)
{
for
(
List
<
Point
>
l
pt
:
pts
)
mats
.
add
(
v
ector_Point_to_Mat
(
lpt
)
);
for
(
CvVectorPoint
v
pt
:
pts
)
mats
.
add
(
v
pt
);
res
=
vector_Mat_to_Mat
(
mats
);
}
else
{
res
=
new
Mat
();
...
...
@@ -483,8 +488,23 @@ public class Converters {
return
res
;
}
public
static
void
Mat_to_vector_vector_Point
(
Mat
m
,
List
<
CvVectorPoint
>
pts
)
{
if
(
pts
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"Output List can't be null"
);
if
(
m
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"Input Mat can't be null"
);
List
<
Mat
>
mats
=
new
ArrayList
<
Mat
>(
m
.
rows
());
Mat_to_vector_Mat
(
m
,
mats
);
for
(
Mat
mi
:
mats
)
{
CvVectorPoint
pt
=
new
CvVectorPoint
(
mi
);
pts
.
add
(
pt
);
}
}
// vector_vector_Point2f
public
static
void
Mat_to_vector_vector_Point2f
(
Mat
m
,
List
<
List
<
Point
>
>
pts
)
{
public
static
void
Mat_to_vector_vector_Point2f
(
Mat
m
,
List
<
CvVectorPoint2f
>
pts
)
{
if
(
pts
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"Output List can't be null"
);
...
...
@@ -494,19 +514,18 @@ public class Converters {
List
<
Mat
>
mats
=
new
ArrayList
<
Mat
>(
m
.
rows
());
Mat_to_vector_Mat
(
m
,
mats
);
for
(
Mat
mi
:
mats
)
{
List
<
Point
>
pt
=
new
ArrayList
<
Point
>();
Mat_to_vector_Point2f
(
mi
,
pt
);
CvVectorPoint2f
pt
=
new
CvVectorPoint2f
(
mi
);
pts
.
add
(
pt
);
}
}
// vector_vector_KeyPoint
public
static
Mat
vector_vector_KeyPoint_to_Mat
(
List
<
List
<
KeyPoint
>
>
kps
,
List
<
Mat
>
mats
)
{
public
static
Mat
vector_vector_KeyPoint_to_Mat
(
List
<
CvVectorKeyPoint
>
kps
,
List
<
Mat
>
mats
)
{
Mat
res
;
int
lCount
=
(
kps
!=
null
)
?
kps
.
size
()
:
0
;
if
(
lCount
>
0
)
{
for
(
List
<
KeyPoint
>
l
kp
:
kps
)
mats
.
add
(
v
ector_KeyPoint_to_Mat
(
lkp
)
);
for
(
CvVectorKeyPoint
v
kp
:
kps
)
mats
.
add
(
v
kp
);
res
=
vector_Mat_to_Mat
(
mats
);
}
else
{
res
=
new
Mat
();
...
...
@@ -514,7 +533,7 @@ public class Converters {
return
res
;
}
public
static
void
Mat_to_vector_vector_KeyPoint
(
Mat
m
,
List
<
List
<
KeyPoint
>
>
kps
)
{
public
static
void
Mat_to_vector_vector_KeyPoint
(
Mat
m
,
List
<
CvVectorKeyPoint
>
kps
)
{
if
(
kps
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"Output List can't be null"
);
...
...
@@ -524,9 +543,8 @@ public class Converters {
List
<
Mat
>
mats
=
new
ArrayList
<
Mat
>(
m
.
rows
());
Mat_to_vector_Mat
(
m
,
mats
);
for
(
Mat
mi
:
mats
)
{
List
<
KeyPoint
>
lkp
=
new
ArrayList
<
KeyPoint
>();
Mat_to_vector_KeyPoint
(
mi
,
lkp
);
kps
.
add
(
lkp
);
CvVectorKeyPoint
vkp
=
new
CvVectorKeyPoint
(
mi
);
kps
.
add
(
vkp
);
}
}
...
...
@@ -600,12 +618,12 @@ public class Converters {
}
// vector_vector_DMatch
public
static
Mat
vector_vector_DMatch_to_Mat
(
List
<
List
<
DMatch
>>
ll
dm
,
List
<
Mat
>
mats
)
{
public
static
Mat
vector_vector_DMatch_to_Mat
(
List
<
CvVectorDMatch
>
lv
dm
,
List
<
Mat
>
mats
)
{
Mat
res
;
int
lCount
=
(
l
ldm
!=
null
)
?
ll
dm
.
size
()
:
0
;
int
lCount
=
(
l
vdm
!=
null
)
?
lv
dm
.
size
()
:
0
;
if
(
lCount
>
0
)
{
for
(
List
<
DMatch
>
ldm
:
ll
dm
)
mats
.
add
(
v
ector_DMatch_to_Mat
(
ldm
)
);
for
(
CvVectorDMatch
vdm
:
lv
dm
)
mats
.
add
(
v
dm
);
res
=
vector_Mat_to_Mat
(
mats
);
}
else
{
res
=
new
Mat
();
...
...
@@ -613,8 +631,8 @@ public class Converters {
return
res
;
}
public
static
void
Mat_to_vector_vector_DMatch
(
Mat
m
,
List
<
List
<
DMatch
>>
ll
dm
)
{
if
(
l
l
dm
==
null
)
public
static
void
Mat_to_vector_vector_DMatch
(
Mat
m
,
List
<
CvVectorDMatch
>
lv
dm
)
{
if
(
l
v
dm
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"Output List can't be null"
);
if
(
m
==
null
)
...
...
@@ -622,20 +640,20 @@ public class Converters {
List
<
Mat
>
mats
=
new
ArrayList
<
Mat
>(
m
.
rows
());
Mat_to_vector_Mat
(
m
,
mats
);
lvdm
.
clear
();
for
(
Mat
mi
:
mats
)
{
List
<
DMatch
>
ldm
=
new
ArrayList
<
DMatch
>();
Mat_to_vector_DMatch
(
mi
,
ldm
);
lldm
.
add
(
ldm
);
CvVectorDMatch
vdm
=
new
CvVectorDMatch
(
mi
);
lvdm
.
add
(
vdm
);
}
}
// vector_vector_char
public
static
Mat
vector_vector_char_to_Mat
(
List
<
List
<
Byte
>>
ll
b
,
List
<
Mat
>
mats
)
{
public
static
Mat
vector_vector_char_to_Mat
(
List
<
CvVectorByte
>
lv
b
,
List
<
Mat
>
mats
)
{
Mat
res
;
int
lCount
=
(
l
lb
!=
null
)
?
ll
b
.
size
()
:
0
;
int
lCount
=
(
l
vb
!=
null
)
?
lv
b
.
size
()
:
0
;
if
(
lCount
>
0
)
{
for
(
List
<
Byte
>
lb
:
ll
b
)
mats
.
add
(
v
ector_char_to_Mat
(
lb
)
);
for
(
CvVectorByte
vb
:
lv
b
)
mats
.
add
(
v
b
);
res
=
vector_Mat_to_Mat
(
mats
);
}
else
{
res
=
new
Mat
();
...
...
samples/android/face-detection/src/org/opencv/samples/fd/FdView.java
View file @
78d92584
...
...
@@ -4,11 +4,10 @@ import java.io.File;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.LinkedList
;
import
java.util.List
;
import
org.opencv.android.Utils
;
import
org.opencv.core.Core
;
import
org.opencv.core.CvVectorRect
;
import
org.opencv.core.Mat
;
import
org.opencv.core.Rect
;
import
org.opencv.core.Scalar
;
...
...
@@ -81,11 +80,12 @@ class FdView extends SampleCvViewBase {
if
(
mCascade
!=
null
)
{
int
height
=
mGray
.
rows
();
int
faceSize
=
Math
.
round
(
height
*
FdActivity
.
minFaceSize
);
List
<
Rect
>
faces
=
new
LinkedList
<
Rect
>
();
CvVectorRect
faces
=
new
CvVectorRect
();
mCascade
.
detectMultiScale
(
mGray
,
faces
,
1.1
,
2
,
2
// TODO: objdetect.CV_HAAR_SCALE_IMAGE
,
new
Size
(
faceSize
,
faceSize
),
new
Size
());
for
(
Rect
r
:
faces
)
Rect
ra
[]
=
null
;
for
(
Rect
r
:
faces
.
toArray
(
ra
))
Core
.
rectangle
(
mRgba
,
r
.
tl
(),
r
.
br
(),
new
Scalar
(
0
,
255
,
0
,
255
),
3
);
}
...
...
samples/android/tutorial-2-opencvcamera/src/org/opencv/samples/tutorial2/Sample2View.java
View file @
78d92584
package
org
.
opencv
.
samples
.
tutorial2
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.opencv.android.Utils
;
import
org.opencv.core.Core
;
import
org.opencv.core.CvVectorPoint
;
import
org.opencv.core.Mat
;
import
org.opencv.core.Point
;
import
org.opencv.core.Scalar
;
import
org.opencv.imgproc.Imgproc
;
import
org.opencv.highgui.Highgui
;
import
org.opencv.highgui.VideoCapture
;
import
org.opencv.imgproc.Imgproc
;
import
android.content.Context
;
import
android.graphics.Bitmap
;
...
...
@@ -18,6 +22,10 @@ class Sample2View extends SampleCvViewBase {
private
Mat
mRgba
;
private
Mat
mGray
;
private
Mat
mIntermediateMat
;
private
Mat
mIntermediateMat2
;
private
Mat
mEmpty
;
private
Scalar
lo
,
hi
;
private
Scalar
bl
,
wh
;
public
Sample2View
(
Context
context
)
{
super
(
context
);
...
...
@@ -32,11 +40,18 @@ class Sample2View extends SampleCvViewBase {
mGray
=
new
Mat
();
mRgba
=
new
Mat
();
mIntermediateMat
=
new
Mat
();
mIntermediateMat2
=
new
Mat
();
mEmpty
=
new
Mat
();
lo
=
new
Scalar
(
85
,
100
,
30
);
hi
=
new
Scalar
(
130
,
255
,
255
);
bl
=
new
Scalar
(
0
,
0
,
0
,
255
);
wh
=
new
Scalar
(
255
,
255
,
255
,
255
);
}
}
@Override
protected
Bitmap
processFrame
(
VideoCapture
capture
)
{
/**/
switch
(
Sample2NativeCamera
.
viewMode
)
{
case
Sample2NativeCamera
.
VIEW_MODE_GRAY
:
capture
.
retrieve
(
mGray
,
Highgui
.
CV_CAP_ANDROID_GREY_FRAME
);
...
...
@@ -44,14 +59,39 @@ class Sample2View extends SampleCvViewBase {
break
;
case
Sample2NativeCamera
.
VIEW_MODE_RGBA
:
capture
.
retrieve
(
mRgba
,
Highgui
.
CV_CAP_ANDROID_COLOR_FRAME_RGBA
);
Core
.
putText
(
mRgba
,
"OpenCV + Android"
,
new
Point
(
10
,
100
),
3
/* CV_FONT_HERSHEY_COMPLEX */
,
2
,
new
Scalar
(
255
,
0
,
0
,
255
),
3
);
Core
.
putText
(
mRgba
,
"OpenCV + Android"
,
new
Point
(
10
,
100
),
3
,
2
,
new
Scalar
(
255
,
0
,
0
,
255
),
3
);
break
;
case
Sample2NativeCamera
.
VIEW_MODE_CANNY
:
capture
.
retrieve
(
mGray
,
Highgui
.
CV_CAP_ANDROID_GREY_FRAME
);
/*
capture.retrieve(mGray, Highgui.CV_CAP_ANDROID_GREY_FRAME);
Imgproc.Canny(mGray, mIntermediateMat, 80, 100);
Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2BGRA, 4);
break
;
*/
capture
.
retrieve
(
mRgba
,
Highgui
.
CV_CAP_ANDROID_COLOR_FRAME_RGBA
);
Imgproc
.
cvtColor
(
mRgba
,
mIntermediateMat
,
Imgproc
.
COLOR_RGB2HSV_FULL
);
Core
.
inRange
(
mIntermediateMat
,
lo
,
hi
,
mIntermediateMat2
);
// green
Imgproc
.
dilate
(
mIntermediateMat2
,
mIntermediateMat2
,
mEmpty
);
//
List
<
CvVectorPoint
>
contours
=
new
ArrayList
<
CvVectorPoint
>();
Mat
hierarchy
=
new
Mat
();
Imgproc
.
findContours
(
mIntermediateMat2
,
contours
,
hierarchy
,
Imgproc
.
RETR_LIST
,
Imgproc
.
CHAIN_APPROX_SIMPLE
);
Log
.
d
(
"processFrame"
,
"contours.size()"
+
contours
.
size
());
double
maxArea
=
0
;
int
indexMaxArea
=
-
1
;
for
(
int
i
=
0
;
i
<
contours
.
size
();
i
++)
{
double
s
=
Imgproc
.
contourArea
(
contours
.
get
(
i
));
if
(
s
>
maxArea
){
indexMaxArea
=
i
;
maxArea
=
s
;
}
}
mRgba
.
setTo
(
bl
);
Imgproc
.
drawContours
(
mRgba
,
contours
,
indexMaxArea
,
wh
);
//
//Imgproc.cvtColor(mIntermediateMat2, mRgba, Imgproc.COLOR_GRAY2RGBA);
break
;
}
/**/
Bitmap
bmp
=
Bitmap
.
createBitmap
(
mRgba
.
cols
(),
mRgba
.
rows
(),
Bitmap
.
Config
.
ARGB_8888
);
...
...
@@ -78,6 +118,9 @@ class Sample2View extends SampleCvViewBase {
if
(
mIntermediateMat
!=
null
)
mIntermediateMat
.
release
();
if
(
mIntermediateMat2
!=
null
)
mIntermediateMat2
.
release
();
mRgba
=
null
;
mGray
=
null
;
mIntermediateMat
=
null
;
...
...
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