Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
e59f5303
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e59f5303
编写于
7月 12, 2011
作者:
L
Leonid Beynenson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added the class RotatedRect to Java API.
Added tests for the class.
上级
b58dc210
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
271 addition
and
9 deletion
+271
-9
modules/java/android_test/src/org/opencv/test/core/RotatedRectTest.java
...ndroid_test/src/org/opencv/test/core/RotatedRectTest.java
+156
-0
modules/java/gen_java.py
modules/java/gen_java.py
+9
-3
modules/java/src/java/Point.java
modules/java/src/java/Point.java
+7
-0
modules/java/src/java/Rect.java
modules/java/src/java/Rect.java
+8
-2
modules/java/src/java/RotatedRect.java
modules/java/src/java/RotatedRect.java
+87
-0
modules/java/src/java/Size.java
modules/java/src/java/Size.java
+4
-4
未找到文件。
modules/java/android_test/src/org/opencv/test/core/RotatedRectTest.java
0 → 100644
浏览文件 @
e59f5303
package
org.opencv.test.core
;
import
org.opencv.Point
;
import
org.opencv.Rect
;
import
org.opencv.RotatedRect
;
import
org.opencv.Size
;
import
org.opencv.test.OpenCVTestCase
;
import
org.opencv.test.OpenCVTestRunner
;
public
class
RotatedRectTest
extends
OpenCVTestCase
{
public
void
testBoundingRect
()
{
Point
center
=
new
Point
(
matSize
/
2
,
matSize
/
2
);
double
length1
=
matSize
/
4
;
Size
size
=
new
Size
(
length1
,
length1
);
double
angle
=
45
;
RotatedRect
rr
=
new
RotatedRect
(
center
,
size
,
angle
);
Rect
r
=
rr
.
boundingRect
();
OpenCVTestRunner
.
Log
(
"testBoundingRect: r="
+
r
.
toString
());
OpenCVTestRunner
.
Log
(
"testBoundingRect: center.x + length1*Math.sqrt(2)/2="
+
(
center
.
x
+
length1
*
Math
.
sqrt
(
2
)/
2
));
OpenCVTestRunner
.
Log
(
"testBoundingRect: length1*Math.sqrt(2)="
+
(
length1
*
Math
.
sqrt
(
2
)));
assertTrue
(
(
r
.
x
==
Math
.
floor
(
center
.
x
-
length1
*
Math
.
sqrt
(
2
)/
2
))
&&
(
r
.
y
==
Math
.
floor
(
center
.
y
-
length1
*
Math
.
sqrt
(
2
)/
2
)));
assertTrue
(
(
r
.
br
().
x
>=
Math
.
ceil
(
center
.
x
+
length1
*
Math
.
sqrt
(
2
)/
2
))
&&
(
r
.
br
().
y
>=
Math
.
ceil
(
center
.
y
+
length1
*
Math
.
sqrt
(
2
)/
2
)));
assertTrue
(
(
r
.
br
().
x
-
Math
.
ceil
(
center
.
x
+
length1
*
Math
.
sqrt
(
2
)/
2
))
<=
1
&&
(
r
.
br
().
y
-
Math
.
ceil
(
center
.
y
+
length1
*
Math
.
sqrt
(
2
)/
2
))
<=
1
);
}
public
void
testClone
()
{
Point
center
=
new
Point
(
matSize
/
2
,
matSize
/
2
);
Size
size
=
new
Size
(
matSize
/
4
,
matSize
/
2
);
double
angle
=
40
;
RotatedRect
rr1
=
new
RotatedRect
(
center
,
size
,
angle
);
RotatedRect
rr1c
=
rr1
.
clone
();
assertTrue
(
rr1c
!=
null
);
assertTrue
(
rr1
.
center
.
equals
(
rr1c
.
center
));
assertTrue
(
rr1
.
size
.
equals
(
rr1c
.
size
));
assertTrue
(
rr1
.
angle
==
rr1c
.
angle
);
}
public
void
testEqualsObject
()
{
Point
center
=
new
Point
(
matSize
/
2
,
matSize
/
2
);
Size
size
=
new
Size
(
matSize
/
4
,
matSize
/
2
);
double
angle
=
40
;
Point
center2
=
new
Point
(
matSize
/
3
,
matSize
/
1.5
);
Size
size2
=
new
Size
(
matSize
/
2
,
matSize
/
4
);
double
angle2
=
0
;
RotatedRect
rr1
=
new
RotatedRect
(
center
,
size
,
angle
);
RotatedRect
rr2
=
new
RotatedRect
(
center2
,
size2
,
angle2
);
RotatedRect
rr1c
=
rr1
.
clone
();
RotatedRect
rr3
=
rr2
.
clone
();
RotatedRect
rr11
=
rr1
;
rr3
.
angle
=
10
;
assertTrue
(
rr1
.
equals
(
rr11
));
assertTrue
(!
rr1
.
equals
(
rr2
));
assertTrue
(
rr1
.
equals
(
rr1c
));
assertTrue
(!
rr2
.
equals
(
rr3
));
rr1c
.
center
.
x
+=
1
;
assertTrue
(!
rr1
.
equals
(
rr1c
));
rr1c
.
center
.
x
-=
1
;
assertTrue
(
rr1
.
equals
(
rr1c
));
rr1c
.
size
.
width
+=
1
;
assertTrue
(!
rr1
.
equals
(
rr1c
));
assertTrue
(!
rr1
.
equals
(
size
));
}
public
void
testPoints
()
{
Point
center
=
new
Point
(
matSize
/
2
,
matSize
/
2
);
Size
size
=
new
Size
(
matSize
/
4
,
matSize
/
2
);
double
angle
=
40
;
RotatedRect
rr
=
new
RotatedRect
(
center
,
size
,
angle
);
Point
p
[]
=
new
Point
[
4
];
rr
.
points
(
p
);
boolean
is_p0_irrational
=
(
100
*
p
[
0
].
x
!=(
int
)(
100
*
p
[
0
].
x
))
&&
(
100
*
p
[
0
].
y
!=(
int
)(
100
*
p
[
0
].
y
));
boolean
is_p1_irrational
=
(
100
*
p
[
1
].
x
!=(
int
)(
100
*
p
[
1
].
x
))
&&
(
100
*
p
[
1
].
y
!=(
int
)(
100
*
p
[
1
].
y
));
boolean
is_p2_irrational
=
(
100
*
p
[
2
].
x
!=(
int
)(
100
*
p
[
2
].
x
))
&&
(
100
*
p
[
2
].
y
!=(
int
)(
100
*
p
[
2
].
y
));
boolean
is_p3_irrational
=
(
100
*
p
[
3
].
x
!=(
int
)(
100
*
p
[
3
].
x
))
&&
(
100
*
p
[
3
].
y
!=(
int
)(
100
*
p
[
3
].
y
));
assertTrue
(
is_p0_irrational
&&
is_p1_irrational
&&
is_p2_irrational
&&
is_p3_irrational
);
assertTrue
(
"Symmetric points 0 and 2"
,
Math
.
abs
((
p
[
0
].
x
+
p
[
2
].
x
)/
2
-
center
.
x
)
+
Math
.
abs
((
p
[
0
].
y
+
p
[
2
].
y
)/
2
-
center
.
y
)
<
0.001
);
assertTrue
(
"Symmetric points 1 and 3"
,
Math
.
abs
((
p
[
1
].
x
+
p
[
3
].
x
)/
2
-
center
.
x
)
+
Math
.
abs
((
p
[
1
].
y
+
p
[
3
].
y
)/
2
-
center
.
y
)
<
0.001
);
assertTrue
(
"Orthogonal vectors 01 and 12"
,
Math
.
abs
(
(
p
[
1
].
x
-
p
[
0
].
x
)
*
(
p
[
2
].
x
-
p
[
1
].
x
)
+
(
p
[
1
].
y
-
p
[
0
].
y
)
*
(
p
[
2
].
y
-
p
[
1
].
y
)
)
<
0.001
);
assertTrue
(
"Orthogonal vectors 12 and 23"
,
Math
.
abs
(
(
p
[
2
].
x
-
p
[
1
].
x
)
*
(
p
[
3
].
x
-
p
[
2
].
x
)
+
(
p
[
2
].
y
-
p
[
1
].
y
)
*
(
p
[
3
].
y
-
p
[
2
].
y
)
)
<
0.001
);
assertTrue
(
"Orthogonal vectors 23 and 30"
,
Math
.
abs
(
(
p
[
3
].
x
-
p
[
2
].
x
)
*
(
p
[
0
].
x
-
p
[
3
].
x
)
+
(
p
[
3
].
y
-
p
[
2
].
y
)
*
(
p
[
0
].
y
-
p
[
3
].
y
)
)
<
0.001
);
assertTrue
(
"Orthogonal vectors 30 and 01"
,
Math
.
abs
(
(
p
[
0
].
x
-
p
[
3
].
x
)
*
(
p
[
1
].
x
-
p
[
0
].
x
)
+
(
p
[
0
].
y
-
p
[
3
].
y
)
*
(
p
[
1
].
y
-
p
[
0
].
y
)
)
<
0.001
);
assertTrue
(
"Length of the vector 01"
,
Math
.
abs
(
(
p
[
1
].
x
-
p
[
0
].
x
)
*
(
p
[
1
].
x
-
p
[
0
].
x
)
+
(
p
[
1
].
y
-
p
[
0
].
y
)*(
p
[
1
].
y
-
p
[
0
].
y
)
-
size
.
height
*
size
.
height
)
<
0.001
);
assertTrue
(
"Length of the vector 21"
,
Math
.
abs
(
(
p
[
1
].
x
-
p
[
2
].
x
)
*
(
p
[
1
].
x
-
p
[
2
].
x
)
+
(
p
[
1
].
y
-
p
[
2
].
y
)*(
p
[
1
].
y
-
p
[
2
].
y
)
-
size
.
width
*
size
.
width
)
<
0.001
);
assertTrue
(
"Angle of the vector 21 with the axes"
,
Math
.
abs
(
(
p
[
2
].
x
-
p
[
1
].
x
)
/
size
.
width
-
Math
.
cos
(
angle
*
Math
.
PI
/
180
)
)
<
0.001
);
}
public
void
testRotatedRect
()
{
RotatedRect
rr
=
new
RotatedRect
();
assertTrue
(
rr
!=
null
);
}
public
void
testRotatedRectPointSizeDouble
()
{
RotatedRect
rr
=
new
RotatedRect
(
new
Point
(
matSize
/
2
,
matSize
/
2
),
new
Size
(
matSize
/
4
,
matSize
/
2
),
45
);
assertTrue
(
rr
!=
null
);
}
}
modules/java/gen_java.py
浏览文件 @
e59f5303
...
...
@@ -46,9 +46,15 @@ type_dict = {
"Rect"
:
{
"j_type"
:
"Rect"
,
"jn_args"
:
((
"int"
,
".x"
),
(
"int"
,
".y"
),
(
"int"
,
".width"
),
(
"int"
,
".height"
)),
"jni_var"
:
"cv::Rect %(n)s(%(n)s_x, %(n)s_y, %(n)s_width, %(n)s_height)"
,
"suffix"
:
"IIII"
},
"Size"
:
{
"j_type"
:
"Size"
,
"jn_args"
:
((
"int"
,
".width"
),
(
"int"
,
".height"
)),
"jni_var"
:
"cv::Size %(n)s(%(n)s_width, %(n)s_height)"
,
"suffix"
:
"II"
},
"Size"
:
{
"j_type"
:
"Size"
,
"jn_args"
:
((
"double"
,
".width"
),
(
"double"
,
".height"
)),
"jni_var"
:
"cv::Size %(n)s((int)%(n)s_width, (int)%(n)s_height)"
,
"suffix"
:
"DD"
},
"Size2f"
:
{
"j_type"
:
"Size"
,
"jn_args"
:
((
"double"
,
".width"
),
(
"double"
,
".height"
)),
"jni_var"
:
"cv::Size2f %(n)s((float)%(n)s_width, (float)%(n)s_height)"
,
"suffix"
:
"DD"
},
"RotatedRect"
:
{
"j_type"
:
"RotatedRect"
,
"jn_args"
:
((
"double"
,
".center.x"
),
(
"double"
,
".center.y"
),
(
"double"
,
".size.width"
),
(
"double"
,
".size.height"
),
(
"double"
,
".angle"
)),
"jni_var"
:
"cv::RotatedRect %(n)s(cv::Point2f(%(n)s_center_x, %(n)s_center_y), cv::Size2f(%(n)s_size_width, %(n)s_size_height), %(n)s_angle)"
,
"suffix"
:
"DDDDD"
},
"Scalar"
:
{
"j_type"
:
"Scalar"
,
"jn_args"
:
((
"double"
,
".v0"
),
(
"double"
,
".v1"
),
(
"double"
,
".v2"
),
(
"double"
,
".v3"
)),
"jni_var"
:
"cv::Scalar %(n)s(%(n)s_v0, %(n)s_v1, %(n)s_v2, %(n)s_v3)"
,
"suffix"
:
"DDDD"
},
...
...
modules/java/src/java/Point.java
浏览文件 @
e59f5303
...
...
@@ -45,4 +45,11 @@ public class Point {
public
boolean
inside
(
Rect
r
)
{
return
r
.
contains
(
this
);
}
@Override
public
String
toString
()
{
if
(
this
==
null
)
return
"null"
;
return
"{"
+
x
+
", "
+
y
+
"}"
;
}
}
modules/java/src/java/Rect.java
浏览文件 @
e59f5303
...
...
@@ -3,7 +3,7 @@ package org.opencv;
//javadoc:Rect_
public
class
Rect
{
int
x
,
y
,
width
,
height
;
public
int
x
,
y
,
width
,
height
;
public
Rect
(
int
x
,
int
y
,
int
width
,
int
height
)
{
this
.
x
=
x
;
...
...
@@ -24,7 +24,7 @@ public class Rect {
}
public
Rect
(
Point
p
,
Size
s
)
{
this
((
int
)
p
.
x
,
(
int
)
p
.
y
,
s
.
width
,
s
.
height
);
this
((
int
)
p
.
x
,
(
int
)
p
.
y
,
(
int
)
s
.
width
,
(
int
)
s
.
height
);
}
public
Rect
clone
()
{
...
...
@@ -74,4 +74,10 @@ public class Rect {
Rect
it
=
(
Rect
)
obj
;
return
x
==
it
.
x
&&
y
==
it
.
y
&&
width
==
it
.
width
&&
height
==
it
.
height
;
}
@Override
public
String
toString
()
{
if
(
this
==
null
)
return
"null"
;
return
"{"
+
x
+
", "
+
y
+
", "
+
width
+
"x"
+
height
+
"}"
;
}
}
modules/java/src/java/RotatedRect.java
0 → 100644
浏览文件 @
e59f5303
package
org.opencv
;
//javadoc:RotatedRect_
public
class
RotatedRect
{
public
Point
center
;
public
Size
size
;
public
double
angle
;
public
RotatedRect
()
{
this
.
angle
=
0
;
}
public
RotatedRect
(
Point
c
,
Size
s
,
double
a
)
{
this
.
center
=
c
.
clone
();
this
.
size
=
s
.
clone
();
this
.
angle
=
a
;
}
public
void
points
(
Point
pt
[])
{
double
_angle
=
angle
*
Math
.
PI
/
180.0
;
double
b
=
(
double
)
Math
.
cos
(
_angle
)*
0.5f
;
double
a
=
(
double
)
Math
.
sin
(
_angle
)*
0.5f
;
pt
[
0
]
=
new
Point
(
center
.
x
-
a
*
size
.
height
-
b
*
size
.
width
,
center
.
y
+
b
*
size
.
height
-
a
*
size
.
width
);
pt
[
1
]
=
new
Point
(
center
.
x
+
a
*
size
.
height
-
b
*
size
.
width
,
center
.
y
-
b
*
size
.
height
-
a
*
size
.
width
);
pt
[
2
]
=
new
Point
(
2
*
center
.
x
-
pt
[
0
].
x
,
2
*
center
.
y
-
pt
[
0
].
y
);
pt
[
3
]
=
new
Point
(
2
*
center
.
x
-
pt
[
1
].
x
,
2
*
center
.
y
-
pt
[
1
].
y
);
}
public
Rect
boundingRect
()
{
Point
pt
[]
=
new
Point
[
4
];
points
(
pt
);
Rect
r
=
new
Rect
((
int
)
Math
.
floor
(
Math
.
min
(
Math
.
min
(
Math
.
min
(
pt
[
0
].
x
,
pt
[
1
].
x
),
pt
[
2
].
x
),
pt
[
3
].
x
)),
(
int
)
Math
.
floor
(
Math
.
min
(
Math
.
min
(
Math
.
min
(
pt
[
0
].
y
,
pt
[
1
].
y
),
pt
[
2
].
y
),
pt
[
3
].
y
)),
(
int
)
Math
.
ceil
(
Math
.
max
(
Math
.
max
(
Math
.
max
(
pt
[
0
].
x
,
pt
[
1
].
x
),
pt
[
2
].
x
),
pt
[
3
].
x
)),
(
int
)
Math
.
ceil
(
Math
.
max
(
Math
.
max
(
Math
.
max
(
pt
[
0
].
y
,
pt
[
1
].
y
),
pt
[
2
].
y
),
pt
[
3
].
y
)));
r
.
width
-=
r
.
x
-
1
;
r
.
height
-=
r
.
y
-
1
;
return
r
;
}
public
RotatedRect
clone
()
{
return
new
RotatedRect
(
center
,
size
,
angle
);
}
@Override
public
int
hashCode
()
{
final
int
prime
=
31
;
int
result
=
1
;
long
temp
;
temp
=
Double
.
doubleToLongBits
(
center
.
x
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
temp
=
Double
.
doubleToLongBits
(
center
.
y
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
temp
=
Double
.
doubleToLongBits
(
size
.
width
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
temp
=
Double
.
doubleToLongBits
(
size
.
height
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
temp
=
Double
.
doubleToLongBits
(
angle
);
result
=
prime
*
result
+
(
int
)
(
temp
^
(
temp
>>>
32
));
return
result
;
}
@Override
public
boolean
equals
(
Object
obj
)
{
if
(
this
==
obj
)
return
true
;
if
(!(
obj
instanceof
RotatedRect
))
return
false
;
RotatedRect
it
=
(
RotatedRect
)
obj
;
return
center
.
equals
(
it
.
center
)
&&
size
.
equals
(
it
.
size
)
&&
angle
==
it
.
angle
;
}
}
modules/java/src/java/Size.java
浏览文件 @
e59f5303
...
...
@@ -3,9 +3,9 @@ package org.opencv;
//javadoc:Size_
public
class
Size
{
public
int
width
,
height
;
public
double
width
,
height
;
public
Size
(
int
width
,
int
height
)
{
public
Size
(
double
width
,
double
height
)
{
this
.
width
=
width
;
this
.
height
=
height
;
}
...
...
@@ -15,8 +15,8 @@ public class Size {
}
public
Size
(
Point
p
)
{
width
=
(
int
)
p
.
x
;
height
=
(
int
)
p
.
y
;
width
=
(
double
)
p
.
x
;
height
=
(
double
)
p
.
y
;
}
public
double
area
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录