mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 14:13:15 +08:00
optimize code
This commit is contained in:
parent
433bc81b30
commit
a1532582a6
@ -2532,29 +2532,29 @@ double cv::solvePoly( InputArray _coeffs0, OutputArray _roots0, int maxIters )
|
||||
for( j = 0; j < square_root_times; j++)
|
||||
{
|
||||
num.re = old_num_re*old_num_re + old_num_im*old_num_im;
|
||||
num.re = std::sqrt(num.re);
|
||||
num.re = sqrt(num.re);
|
||||
num.re += old_num_re;
|
||||
num.im = num.re - old_num_re;
|
||||
num.re /= 2;
|
||||
num.re = std::sqrt(num.re);
|
||||
num.re = sqrt(num.re);
|
||||
|
||||
num.im /= 2;
|
||||
num.im = std::sqrt(num.im);
|
||||
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) = -(std::pow(old_num_re, 3));
|
||||
cube_coefs.at<double>(2) = -(15*std::pow(old_num_re, 2) + 27*std::pow(old_num_im, 2));
|
||||
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;
|
||||
cv::solveCubic(cube_coefs, cube_roots);
|
||||
solveCubic(cube_coefs, cube_roots);
|
||||
|
||||
num.re = std::pow(std::abs(cube_roots.at<double>(0)), 1/3);
|
||||
if(cube_roots.at<double>(0) < 0) num.re = -num.re;
|
||||
num.im = std::sqrt(std::pow(num.re, 2) / 3 - old_num_re / (3*num.re));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user