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
ddf293a0
Commit
ddf293a0
authored
Nov 22, 2015
by
Maksim Shabunin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5649 from hoangviet1985:solve_pow(x,3)=0_opencv300
parents
f019de69
3e96b724
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
5 deletions
+33
-5
mathfuncs.cpp
modules/core/src/mathfuncs.cpp
+22
-5
test_math.cpp
modules/core/test/test_math.cpp
+11
-0
No files found.
modules/core/src/mathfuncs.cpp
View file @
ddf293a0
...
@@ -44,6 +44,7 @@
...
@@ -44,6 +44,7 @@
#include "precomp.hpp"
#include "precomp.hpp"
#include "opencl_kernels_core.hpp"
#include "opencl_kernels_core.hpp"
#include <limits>
#include <limits>
#include <iostream>
namespace
cv
namespace
cv
{
{
...
@@ -1998,10 +1999,10 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots )
...
@@ -1998,10 +1999,10 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots )
double
Qcubed
=
Q
*
Q
*
Q
;
double
Qcubed
=
Q
*
Q
*
Q
;
double
d
=
Qcubed
-
R
*
R
;
double
d
=
Qcubed
-
R
*
R
;
if
(
d
>
=
0
)
if
(
d
>
0
)
{
{
double
theta
=
acos
(
R
/
s
td
::
s
qrt
(
Qcubed
));
double
theta
=
acos
(
R
/
sqrt
(
Qcubed
));
double
sqrtQ
=
s
td
::
s
qrt
(
Q
);
double
sqrtQ
=
sqrt
(
Q
);
double
t0
=
-
2
*
sqrtQ
;
double
t0
=
-
2
*
sqrtQ
;
double
t1
=
theta
*
(
1.
/
3
);
double
t1
=
theta
*
(
1.
/
3
);
double
t2
=
a1
*
(
1.
/
3
);
double
t2
=
a1
*
(
1.
/
3
);
...
@@ -2010,11 +2011,27 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots )
...
@@ -2010,11 +2011,27 @@ int cv::solveCubic( InputArray _coeffs, OutputArray _roots )
x2
=
t0
*
cos
(
t1
+
(
4.
*
CV_PI
/
3
))
-
t2
;
x2
=
t0
*
cos
(
t1
+
(
4.
*
CV_PI
/
3
))
-
t2
;
n
=
3
;
n
=
3
;
}
}
else
if
(
d
==
0
)
{
if
(
R
>=
0
)
{
x0
=
-
2
*
pow
(
R
,
1.
/
3
)
-
a1
/
3
;
x1
=
pow
(
R
,
1.
/
3
)
-
a1
/
3
;
}
else
{
x0
=
2
*
pow
(
-
R
,
1.
/
3
)
-
a1
/
3
;
x1
=
-
pow
(
-
R
,
1.
/
3
)
-
a1
/
3
;
}
x2
=
0
;
n
=
x0
==
x1
?
1
:
2
;
x1
=
x0
==
x1
?
0
:
x1
;
}
else
else
{
{
double
e
;
double
e
;
d
=
s
td
::
s
qrt
(
-
d
);
d
=
sqrt
(
-
d
);
e
=
std
::
pow
(
d
+
fabs
(
R
),
0.33333333333
3
);
e
=
pow
(
d
+
fabs
(
R
),
1.
/
3
);
if
(
R
>
0
)
if
(
R
>
0
)
e
=
-
e
;
e
=
-
e
;
x0
=
(
e
+
Q
/
e
)
-
a1
*
(
1.
/
3
);
x0
=
(
e
+
Q
/
e
)
-
a1
*
(
1.
/
3
);
...
...
modules/core/test/test_math.cpp
View file @
ddf293a0
...
@@ -2330,6 +2330,17 @@ void Core_SolvePolyTest::run( int )
...
@@ -2330,6 +2330,17 @@ void Core_SolvePolyTest::run( int )
pass
=
pass
&&
div
<
err_eps
;
pass
=
pass
&&
div
<
err_eps
;
}
}
//test x^3 = 0
cv
::
Mat
coeffs_5623
(
4
,
1
,
CV_64FC1
);
cv
::
Mat
r_5623
(
3
,
1
,
CV_64FC2
);
coeffs_5623
.
at
<
double
>
(
0
)
=
1
;
coeffs_5623
.
at
<
double
>
(
1
)
=
0
;
coeffs_5623
.
at
<
double
>
(
2
)
=
0
;
coeffs_5623
.
at
<
double
>
(
3
)
=
0
;
double
prec_5623
=
cv
::
solveCubic
(
coeffs_5623
,
r_5623
);
pass
=
pass
&&
r_5623
.
at
<
double
>
(
0
)
==
0
&&
r_5623
.
at
<
double
>
(
1
)
==
0
&&
r_5623
.
at
<
double
>
(
2
)
==
0
;
pass
=
pass
&&
prec_5623
==
1
;
if
(
!
pass
)
if
(
!
pass
)
{
{
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_OUTPUT
);
ts
->
set_failed_test_info
(
cvtest
::
TS
::
FAIL_INVALID_OUTPUT
);
...
...
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