Skip to content

Commit 9bf6ec6

Browse files
committed
Revert "Adapted estimateNewCameraMatrix to make it work with pincushion-like distortion."
This reverts commit 5384a22.
1 parent cc2ee92 commit 9bf6ec6

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

modules/calib3d/src/fisheye.cpp

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,12 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input
547547
int w = image_size.width, h = image_size.height;
548548
balance = std::min(std::max(balance, 0.0), 1.0);
549549

550-
cv::Mat points(1, 8, CV_64FC2);
550+
cv::Mat points(1, 4, CV_64FC2);
551551
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);
560556

561557
fisheye::undistortPoints(points, points, K, D, R);
562558
cv::Scalar center_mass = mean(points);
@@ -573,23 +569,19 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input
573569
double minx = DBL_MAX, miny = DBL_MAX, maxx = -DBL_MAX, maxy = -DBL_MAX;
574570
for(size_t i = 0; i < points.total(); ++i)
575571
{
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]);
584576
}
585577

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]);
590582

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)));
593585

594586
double f = balance * fmin + (1.0 - balance) * fmax;
595587
f *= fov_scale > 0 ? 1.0/fov_scale : 1.0;

0 commit comments

Comments
 (0)