Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
b96def88
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,发现更多精彩内容 >>
提交
b96def88
编写于
11月 20, 2015
作者:
H
hoangviet1985
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
squash
上级
6e2a68fd
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
91 addition
and
1 deletion
+91
-1
modules/core/src/mathfuncs.cpp
modules/core/src/mathfuncs.cpp
+42
-1
modules/core/test/test_math.cpp
modules/core/test/test_math.cpp
+49
-0
未找到文件。
modules/core/src/mathfuncs.cpp
浏览文件 @
b96def88
...
@@ -2085,12 +2085,53 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters )
...
@@ -2085,12 +2085,53 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters )
{
{
p
=
roots
[
i
];
p
=
roots
[
i
];
C
num
=
coeffs
[
n
],
denom
=
coeffs
[
n
];
C
num
=
coeffs
[
n
],
denom
=
coeffs
[
n
];
int
num_same_root
=
1
;
for
(
j
=
0
;
j
<
n
;
j
++
)
for
(
j
=
0
;
j
<
n
;
j
++
)
{
{
num
=
num
*
p
+
coeffs
[
n
-
j
-
1
];
num
=
num
*
p
+
coeffs
[
n
-
j
-
1
];
if
(
j
!=
i
)
denom
=
denom
*
(
p
-
roots
[
j
]);
if
(
j
!=
i
)
{
if
(
(
p
-
roots
[
j
]).
re
!=
0
||
(
p
-
roots
[
j
]).
im
!=
0
)
denom
=
denom
*
(
p
-
roots
[
j
]);
else
num_same_root
++
;
}
}
}
num
/=
denom
;
num
/=
denom
;
if
(
num_same_root
>
1
)
{
double
old_num_re
=
num
.
re
;
double
old_num_im
=
num
.
im
;
int
square_root_times
=
num_same_root
%
2
==
0
?
num_same_root
/
2
:
num_same_root
/
2
-
1
;
for
(
j
=
0
;
j
<
square_root_times
;
j
++
)
{
num
.
re
=
old_num_re
*
old_num_re
+
old_num_im
*
old_num_im
;
num
.
re
=
sqrt
(
num
.
re
);
num
.
re
+=
old_num_re
;
num
.
im
=
num
.
re
-
old_num_re
;
num
.
re
/=
2
;
num
.
re
=
sqrt
(
num
.
re
);
num
.
im
/=
2
;
num
.
im
=
sqrt
(
num
.
im
);
if
(
old_num_re
<
0
)
num
.
im
=
-
num
.
im
;
}
if
(
num_same_root
%
2
!=
0
){
Mat
cube_coefs
(
4
,
1
,
CV_64FC1
);
Mat
cube_roots
(
3
,
1
,
CV_64FC2
);
cube_coefs
.
at
<
double
>
(
3
)
=
-
(
pow
(
old_num_re
,
3
));
cube_coefs
.
at
<
double
>
(
2
)
=
-
(
15
*
pow
(
old_num_re
,
2
)
+
27
*
pow
(
old_num_im
,
2
));
cube_coefs
.
at
<
double
>
(
1
)
=
-
48
*
old_num_re
;
cube_coefs
.
at
<
double
>
(
0
)
=
64
;
solveCubic
(
cube_coefs
,
cube_roots
);
if
(
cube_roots
.
at
<
double
>
(
0
)
>=
0
)
num
.
re
=
pow
(
cube_roots
.
at
<
double
>
(
0
),
1.
/
3
);
else
num
.
re
=
-
pow
(
-
cube_roots
.
at
<
double
>
(
0
),
1.
/
3
);
num
.
im
=
sqrt
(
pow
(
num
.
re
,
2
)
/
3
-
old_num_re
/
(
3
*
num
.
re
));
}
}
roots
[
i
]
=
p
-
num
;
roots
[
i
]
=
p
-
num
;
maxDiff
=
std
::
max
(
maxDiff
,
cv
::
abs
(
num
));
maxDiff
=
std
::
max
(
maxDiff
,
cv
::
abs
(
num
));
}
}
...
...
modules/core/test/test_math.cpp
浏览文件 @
b96def88
...
@@ -2349,6 +2349,55 @@ void Core_SolvePolyTest::run( int )
...
@@ -2349,6 +2349,55 @@ void Core_SolvePolyTest::run( int )
}
}
}
}
template
<
typename
T
>
static
void
checkRoot
(
Mat
&
r
,
T
re
,
T
im
)
{
for
(
int
i
=
0
;
i
<
r
.
cols
*
r
.
rows
;
i
++
)
{
Vec
<
T
,
2
>
v
=
*
(
Vec
<
T
,
2
>*
)
r
.
ptr
(
i
);
if
(
fabs
(
re
-
v
[
0
])
<
1e-6
&&
fabs
(
im
-
v
[
1
])
<
1e-6
)
{
v
[
0
]
=
std
::
numeric_limits
<
T
>::
quiet_NaN
();
v
[
1
]
=
std
::
numeric_limits
<
T
>::
quiet_NaN
();
return
;
}
}
GTEST_NONFATAL_FAILURE_
(
"Can't find root"
)
<<
"("
<<
re
<<
", "
<<
im
<<
")"
;
}
TEST
(
Core_SolvePoly
,
regression_5599
)
{
// x^4 - x^2 = 0, roots: 1, -1, 0, 0
cv
::
Mat
coefs
=
(
cv
::
Mat_
<
float
>
(
1
,
5
)
<<
0
,
0
,
-
1
,
0
,
1
);
{
cv
::
Mat
r
;
double
prec
;
prec
=
cv
::
solvePoly
(
coefs
,
r
);
EXPECT_LE
(
prec
,
1e-6
);
EXPECT_EQ
(
4
,
r
.
total
());
//std::cout << "Preciseness = " << prec << std::endl;
//std::cout << "roots:\n" << r << "\n" << std::endl;
ASSERT_EQ
(
CV_32FC2
,
r
.
type
());
checkRoot
<
float
>
(
r
,
1
,
0
);
checkRoot
<
float
>
(
r
,
-
1
,
0
);
checkRoot
<
float
>
(
r
,
0
,
0
);
checkRoot
<
float
>
(
r
,
0
,
0
);
}
// x^2 - 2x + 1 = 0, roots: 1, 1
coefs
=
(
cv
::
Mat_
<
float
>
(
1
,
3
)
<<
1
,
-
2
,
1
);
{
cv
::
Mat
r
;
double
prec
;
prec
=
cv
::
solvePoly
(
coefs
,
r
);
EXPECT_LE
(
prec
,
1e-6
);
EXPECT_EQ
(
2
,
r
.
total
());
//std::cout << "Preciseness = " << prec << std::endl;
//std::cout << "roots:\n" << r << "\n" << std::endl;
ASSERT_EQ
(
CV_32FC2
,
r
.
type
());
checkRoot
<
float
>
(
r
,
1
,
0
);
checkRoot
<
float
>
(
r
,
1
,
0
);
}
}
class
Core_PhaseTest
:
public
cvtest
::
BaseTest
class
Core_PhaseTest
:
public
cvtest
::
BaseTest
{
{
public:
public:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录