@@ -547,16 +547,12 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input
547
547
int w = image_size.width , h = image_size.height ;
548
548
balance = std::min (std::max (balance, 0.0 ), 1.0 );
549
549
550
- cv::Mat points (1 , 8 , CV_64FC2);
550
+ cv::Mat points (1 , 4 , CV_64FC2);
551
551
Vec2d* pptr = points.ptr <Vec2d>();
552
- pptr[0 ] = Vec2d (0 , 0 );
553
- pptr[1 ] = Vec2d (w/2 , 0 );
554
- pptr[2 ] = Vec2d (w, 0 );
555
- pptr[3 ] = Vec2d (w, h/2 );
556
- pptr[4 ] = Vec2d (w, h);
557
- pptr[5 ] = Vec2d (w/2 , h);
558
- pptr[6 ] = Vec2d (0 , h);
559
- pptr[7 ] = Vec2d (0 , h/2 );
552
+ pptr[0 ] = Vec2d (w/2 , 0 );
553
+ pptr[1 ] = Vec2d (w, h/2 );
554
+ pptr[2 ] = Vec2d (w/2 , h);
555
+ pptr[3 ] = Vec2d (0 , h/2 );
560
556
561
557
fisheye::undistortPoints (points, points, K, D, R);
562
558
cv::Scalar center_mass = mean (points);
@@ -573,23 +569,19 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input
573
569
double minx = DBL_MAX, miny = DBL_MAX, maxx = -DBL_MAX, maxy = -DBL_MAX;
574
570
for (size_t i = 0 ; i < points.total (); ++i)
575
571
{
576
- if (i!=1 && i!=5 ){
577
- minx = std::min (minx, std::abs (pptr[i][0 ]-cn[0 ]));
578
- }
579
- if (i!=3 && i!=7 ){
580
- miny = std::min (miny, std::abs (pptr[i][1 ]-cn[1 ]));
581
- }
582
- maxy = std::max (maxy, std::abs (pptr[i][1 ]-cn[1 ]));
583
- maxx = std::max (maxx, std::abs (pptr[i][0 ]-cn[0 ]));
572
+ miny = std::min (miny, pptr[i][1 ]);
573
+ maxy = std::max (maxy, pptr[i][1 ]);
574
+ minx = std::min (minx, pptr[i][0 ]);
575
+ maxx = std::max (maxx, pptr[i][0 ]);
584
576
}
585
577
586
- double f1 = w * 0.5 /(minx);
587
- double f2 = w * 0.5 /(maxx);
588
- double f3 = h * 0.5 * aspect_ratio/(miny);
589
- double f4 = h * 0.5 * aspect_ratio/(maxy);
578
+ double f1 = w * 0.5 /(cn[ 0 ] - minx);
579
+ double f2 = w * 0.5 /(maxx - cn[ 0 ] );
580
+ double f3 = h * 0.5 * aspect_ratio/(cn[ 1 ] - miny);
581
+ double f4 = h * 0.5 * aspect_ratio/(maxy - cn[ 1 ] );
590
582
591
- double fmax = std::max (f1, f3 );
592
- double fmin = std::min ( f2, f4 );
583
+ double fmin = std::min (f1, std::min (f2, std::min (f3, f4)) );
584
+ double fmax = std::max (f1, std::max ( f2, std::max (f3, f4)) );
593
585
594
586
double f = balance * fmin + (1.0 - balance) * fmax;
595
587
f *= fov_scale > 0 ? 1.0 /fov_scale : 1.0 ;
0 commit comments