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
ec5038f2
Commit
ec5038f2
authored
8 years ago
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7947 from utibenkei:tracking-module-java
parents
97f5d05d
579ffbf9
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
239 additions
and
1 deletion
+239
-1
core+MatOfRect2d.java
modules/core/misc/java/src/java/core+MatOfRect2d.java
+81
-0
core+Rect2d.java
modules/core/misc/java/src/java/core+Rect2d.java
+100
-0
gen_java.py
modules/java/generator/gen_java.py
+5
-1
converters.cpp
modules/java/generator/src/cpp/converters.cpp
+13
-0
converters.h
modules/java/generator/src/cpp/converters.h
+3
-0
utils+Converters.java
modules/java/generator/src/java/utils+Converters.java
+37
-0
No files found.
modules/core/misc/java/src/java/core+MatOfRect2d.java
0 → 100644
View file @
ec5038f2
package
org
.
opencv
.
core
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
MatOfRect2d
extends
Mat
{
// 64FC4
private
static
final
int
_depth
=
CvType
.
CV_64F
;
private
static
final
int
_channels
=
4
;
public
MatOfRect2d
()
{
super
();
}
protected
MatOfRect2d
(
long
addr
)
{
super
(
addr
);
if
(
!
empty
()
&&
checkVector
(
_channels
,
_depth
)
<
0
)
throw
new
IllegalArgumentException
(
"Incompatible Mat"
);
//FIXME: do we need release() here?
}
public
static
MatOfRect2d
fromNativeAddr
(
long
addr
)
{
return
new
MatOfRect2d
(
addr
);
}
public
MatOfRect2d
(
Mat
m
)
{
super
(
m
,
Range
.
all
());
if
(
!
empty
()
&&
checkVector
(
_channels
,
_depth
)
<
0
)
throw
new
IllegalArgumentException
(
"Incompatible Mat"
);
//FIXME: do we need release() here?
}
public
MatOfRect2d
(
Rect2d
...
a
)
{
super
();
fromArray
(
a
);
}
public
void
alloc
(
int
elemNumber
)
{
if
(
elemNumber
>
0
)
super
.
create
(
elemNumber
,
1
,
CvType
.
makeType
(
_depth
,
_channels
));
}
public
void
fromArray
(
Rect2d
...
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
++)
{
Rect2d
r
=
a
[
i
];
buff
[
_channels
*
i
+
0
]
=
(
double
)
r
.
x
;
buff
[
_channels
*
i
+
1
]
=
(
double
)
r
.
y
;
buff
[
_channels
*
i
+
2
]
=
(
double
)
r
.
width
;
buff
[
_channels
*
i
+
3
]
=
(
double
)
r
.
height
;
}
put
(
0
,
0
,
buff
);
//TODO: check ret val!
}
public
Rect2d
[]
toArray
()
{
int
num
=
(
int
)
total
();
Rect2d
[]
a
=
new
Rect2d
[
num
];
if
(
num
==
0
)
return
a
;
double
buff
[]
=
new
double
[
num
*
_channels
];
get
(
0
,
0
,
buff
);
//TODO: check ret val!
for
(
int
i
=
0
;
i
<
num
;
i
++)
a
[
i
]
=
new
Rect2d
(
buff
[
i
*
_channels
],
buff
[
i
*
_channels
+
1
],
buff
[
i
*
_channels
+
2
],
buff
[
i
*
_channels
+
3
]);
return
a
;
}
public
void
fromList
(
List
<
Rect2d
>
lr
)
{
Rect2d
ap
[]
=
lr
.
toArray
(
new
Rect2d
[
0
]);
fromArray
(
ap
);
}
public
List
<
Rect2d
>
toList
()
{
Rect2d
[]
ar
=
toArray
();
return
Arrays
.
asList
(
ar
);
}
}
This diff is collapsed.
Click to expand it.
modules/core/misc/java/src/java/core+Rect2d.java
0 → 100644
View file @
ec5038f2
package
org
.
opencv
.
core
;
//javadoc:Rect2d_
public
class
Rect2d
{
public
double
x
,
y
,
width
,
height
;
public
Rect2d
(
double
x
,
double
y
,
double
width
,
double
height
)
{
this
.
x
=
x
;
this
.
y
=
y
;
this
.
width
=
width
;
this
.
height
=
height
;
}
public
Rect2d
()
{
this
(
0
,
0
,
0
,
0
);
}
public
Rect2d
(
Point
p1
,
Point
p2
)
{
x
=
(
double
)
(
p1
.
x
<
p2
.
x
?
p1
.
x
:
p2
.
x
);
y
=
(
double
)
(
p1
.
y
<
p2
.
y
?
p1
.
y
:
p2
.
y
);
width
=
(
double
)
(
p1
.
x
>
p2
.
x
?
p1
.
x
:
p2
.
x
)
-
x
;
height
=
(
double
)
(
p1
.
y
>
p2
.
y
?
p1
.
y
:
p2
.
y
)
-
y
;
}
public
Rect2d
(
Point
p
,
Size
s
)
{
this
((
double
)
p
.
x
,
(
double
)
p
.
y
,
(
double
)
s
.
width
,
(
double
)
s
.
height
);
}
public
Rect2d
(
double
[]
vals
)
{
set
(
vals
);
}
public
void
set
(
double
[]
vals
)
{
if
(
vals
!=
null
)
{
x
=
vals
.
length
>
0
?
(
double
)
vals
[
0
]
:
0
;
y
=
vals
.
length
>
1
?
(
double
)
vals
[
1
]
:
0
;
width
=
vals
.
length
>
2
?
(
double
)
vals
[
2
]
:
0
;
height
=
vals
.
length
>
3
?
(
double
)
vals
[
3
]
:
0
;
}
else
{
x
=
0
;
y
=
0
;
width
=
0
;
height
=
0
;
}
}
public
Rect2d
clone
()
{
return
new
Rect2d
(
x
,
y
,
width
,
height
);
}
public
Point
tl
()
{
return
new
Point
(
x
,
y
);
}
public
Point
br
()
{
return
new
Point
(
x
+
width
,
y
+
height
);
}
public
Size
size
()
{
return
new
Size
(
width
,
height
);
}
public
double
area
()
{
return
width
*
height
;
}
public
boolean
contains
(
Point
p
)
{
return
x
<=
p
.
x
&&
p
.
x
<
x
+
width
&&
y
<=
p
.
y
&&
p
.
y
<
y
+
height
;
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
long
temp
;
temp
=
Double
.
doubleToLongBits
(
height
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
temp
=
Double
.
doubleToLongBits
(
width
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
temp
=
Double
.
doubleToLongBits
(
x
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
temp
=
Double
.
doubleToLongBits
(
y
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(!(
obj
instanceof
Rect2d
))
return
false
;
Rect2d
it
=
(
Rect2d
)
obj
;
return
x
==
it
.
x
&&
y
==
it
.
y
&&
width
==
it
.
width
&&
height
==
it
.
height
;
}
@Override
public
String
toString
()
{
return
"{"
+
x
+
", "
+
y
+
", "
+
width
+
"x"
+
height
+
"}"
;
}
}
This diff is collapsed.
Click to expand it.
modules/java/generator/gen_java.py
View file @
ec5038f2
...
...
@@ -207,6 +207,7 @@ type_dict = {
"vector_KeyPoint"
:
{
"j_type"
:
"MatOfKeyPoint"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"jni_var"
:
"std::vector<KeyPoint>
%(n)
s"
,
"suffix"
:
"J"
},
"vector_DMatch"
:
{
"j_type"
:
"MatOfDMatch"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"jni_var"
:
"std::vector<DMatch>
%(n)
s"
,
"suffix"
:
"J"
},
"vector_Rect"
:
{
"j_type"
:
"MatOfRect"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"jni_var"
:
"std::vector<Rect>
%(n)
s"
,
"suffix"
:
"J"
},
"vector_Rect2d"
:
{
"j_type"
:
"MatOfRect2d"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"jni_var"
:
"std::vector<Rect2d>
%(n)
s"
,
"suffix"
:
"J"
},
"vector_uchar"
:
{
"j_type"
:
"MatOfByte"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"jni_var"
:
"std::vector<uchar>
%(n)
s"
,
"suffix"
:
"J"
},
"vector_char"
:
{
"j_type"
:
"MatOfByte"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"jni_var"
:
"std::vector<char>
%(n)
s"
,
"suffix"
:
"J"
},
"vector_int"
:
{
"j_type"
:
"MatOfInt"
,
"jn_type"
:
"long"
,
"jni_type"
:
"jlong"
,
"jni_var"
:
"std::vector<int>
%(n)
s"
,
"suffix"
:
"J"
},
...
...
@@ -261,6 +262,9 @@ type_dict = {
"Rect"
:
{
"j_type"
:
"Rect"
,
"jn_args"
:
((
"int"
,
".x"
),
(
"int"
,
".y"
),
(
"int"
,
".width"
),
(
"int"
,
".height"
)),
"jni_var"
:
"Rect
%(n)
s(
%(n)
s_x,
%(n)
s_y,
%(n)
s_width,
%(n)
s_height)"
,
"jni_type"
:
"jdoubleArray"
,
"suffix"
:
"IIII"
},
"Rect2d"
:
{
"j_type"
:
"Rect2d"
,
"jn_args"
:
((
"double"
,
".x"
),
(
"double"
,
".y"
),
(
"double"
,
".width"
),
(
"double"
,
".height"
)),
"jni_var"
:
"Rect
%(n)
s(
%(n)
s_x,
%(n)
s_y,
%(n)
s_width,
%(n)
s_height)"
,
"jni_type"
:
"jdoubleArray"
,
"suffix"
:
"DDDD"
},
"Size"
:
{
"j_type"
:
"Size"
,
"jn_args"
:
((
"double"
,
".width"
),
(
"double"
,
".height"
)),
"jni_var"
:
"Size
%(n)
s((int)
%(n)
s_width, (int)
%(n)
s_height)"
,
"jni_type"
:
"jdoubleArray"
,
"suffix"
:
"DD"
},
...
...
@@ -825,7 +829,7 @@ class ClassInfo(GeneralInfo):
j_type
=
type_dict
[
ctype
][
'j_type'
]
elif
ctype
in
(
"Algorithm"
):
j_type
=
ctype
if
j_type
in
(
"CvType"
,
"Mat"
,
"Point"
,
"Point3"
,
"Range"
,
"Rect"
,
"RotatedRect"
,
"Scalar"
,
"Size"
,
"TermCriteria"
,
"Algorithm"
):
if
j_type
in
(
"CvType"
,
"Mat"
,
"Point"
,
"Point3"
,
"Range"
,
"Rect"
,
"R
ect2d"
,
"R
otatedRect"
,
"Scalar"
,
"Size"
,
"TermCriteria"
,
"Algorithm"
):
self
.
imports
.
add
(
"org.opencv.core."
+
j_type
)
if
j_type
==
'String'
:
self
.
imports
.
add
(
"java.lang.String"
)
...
...
This diff is collapsed.
Click to expand it.
modules/java/generator/src/cpp/converters.cpp
View file @
ec5038f2
...
...
@@ -92,6 +92,19 @@ void vector_Rect_to_Mat(std::vector<Rect>& v_rect, Mat& mat)
mat
=
Mat
(
v_rect
,
true
);
}
//vector_Rect2d
void
Mat_to_vector_Rect2d
(
Mat
&
mat
,
std
::
vector
<
Rect2d
>&
v_rect
)
{
v_rect
.
clear
();
CHECK_MAT
(
mat
.
type
()
==
CV_64FC4
&&
mat
.
cols
==
1
);
v_rect
=
(
std
::
vector
<
Rect2d
>
)
mat
;
}
void
vector_Rect2d_to_Mat
(
std
::
vector
<
Rect2d
>&
v_rect
,
Mat
&
mat
)
{
mat
=
Mat
(
v_rect
,
true
);
}
//vector_Point
void
Mat_to_vector_Point
(
Mat
&
mat
,
std
::
vector
<
Point
>&
v_point
)
...
...
This diff is collapsed.
Click to expand it.
modules/java/generator/src/cpp/converters.h
View file @
ec5038f2
...
...
@@ -19,6 +19,9 @@ void vector_char_to_Mat(std::vector<char>& v_char, cv::Mat& mat);
void
Mat_to_vector_Rect
(
cv
::
Mat
&
mat
,
std
::
vector
<
cv
::
Rect
>&
v_rect
);
void
vector_Rect_to_Mat
(
std
::
vector
<
cv
::
Rect
>&
v_rect
,
cv
::
Mat
&
mat
);
void
Mat_to_vector_Rect2d
(
cv
::
Mat
&
mat
,
std
::
vector
<
cv
::
Rect2d
>&
v_rect
);
void
vector_Rect2d_to_Mat
(
std
::
vector
<
cv
::
Rect2d
>&
v_rect
,
cv
::
Mat
&
mat
);
void
Mat_to_vector_Point
(
cv
::
Mat
&
mat
,
std
::
vector
<
cv
::
Point
>&
v_point
);
void
Mat_to_vector_Point2f
(
cv
::
Mat
&
mat
,
std
::
vector
<
cv
::
Point2f
>&
v_point
);
...
...
This diff is collapsed.
Click to expand it.
modules/java/generator/src/java/utils+Converters.java
View file @
ec5038f2
...
...
@@ -14,6 +14,7 @@ import org.opencv.core.MatOfPoint3f;
import
org.opencv.core.Point
;
import
org.opencv.core.Point3
;
import
org.opencv.core.Rect
;
import
org.opencv.core.Rect2d
;
import
org.opencv.core.DMatch
;
import
org.opencv.core.KeyPoint
;
...
...
@@ -435,6 +436,42 @@ public class Converters {
}
}
public
static
Mat
vector_Rect2d_to_Mat
(
List
<
Rect2d
>
rs
)
{
Mat
res
;
int
count
=
(
rs
!=
null
)
?
rs
.
size
()
:
0
;
if
(
count
>
0
)
{
res
=
new
Mat
(
count
,
1
,
CvType
.
CV_64FC4
);
double
[]
buff
=
new
double
[
4
*
count
];
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
Rect2d
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_Rect2d
(
Mat
m
,
List
<
Rect2d
>
rs
)
{
if
(
rs
==
null
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"rs == null"
);
int
count
=
m
.
rows
();
if
(
CvType
.
CV_64FC4
!=
m
.
type
()
||
m
.
cols
()
!=
1
)
throw
new
java
.
lang
.
IllegalArgumentException
(
"CvType.CV_64FC4 != m.type() || m.rows()!=1\n"
+
m
);
rs
.
clear
();
double
[]
buff
=
new
double
[
4
*
count
];
m
.
get
(
0
,
0
,
buff
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
rs
.
add
(
new
Rect2d
(
buff
[
4
*
i
],
buff
[
4
*
i
+
1
],
buff
[
4
*
i
+
2
],
buff
[
4
*
i
+
3
]));
}
}
public
static
Mat
vector_KeyPoint_to_Mat
(
List
<
KeyPoint
>
kps
)
{
Mat
res
;
int
count
=
(
kps
!=
null
)
?
kps
.
size
()
:
0
;
...
...
This diff is collapsed.
Click to expand it.
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