@@ -517,12 +517,16 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input
517
517
int w = image_size.width , h = image_size.height ;
518
518
balance = std::min (std::max (balance, 0.0 ), 1.0 );
519
519
520
- cv::Mat points (1 , 4 , CV_64FC2);
520
+ cv::Mat points (1 , 8 , CV_64FC2);
521
521
Vec2d* pptr = points.ptr <Vec2d>();
522
- pptr[0 ] = Vec2d (w/2 , 0 );
523
- pptr[1 ] = Vec2d (w, h/2 );
524
- pptr[2 ] = Vec2d (w/2 , h);
525
- pptr[3 ] = Vec2d (0 , h/2 );
522
+ pptr[0 ] = Vec2d (0 , 0 );
523
+ pptr[1 ] = Vec2d (w/2 , 0 );
524
+ pptr[2 ] = Vec2d (w, 0 );
525
+ pptr[3 ] = Vec2d (w, h/2 );
526
+ pptr[4 ] = Vec2d (w, h);
527
+ pptr[5 ] = Vec2d (w/2 , h);
528
+ pptr[6 ] = Vec2d (0 , h);
529
+ pptr[7 ] = Vec2d (0 , h/2 );
526
530
527
531
#if 0
528
532
const int N = 10;
@@ -532,7 +536,6 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input
532
536
{
533
537
pptr[k++] = Vec2d(w/2, 0) - Vec2d(w/8, 0) + Vec2d(w/4/N*i, 0);
534
538
pptr[k++] = Vec2d(w/2, h-1) - Vec2d(w/8, h-1) + Vec2d(w/4/N*i, h-1);
535
-
536
539
pptr[k++] = Vec2d(0, h/2) - Vec2d(0, h/8) + Vec2d(0, h/4/N*i);
537
540
pptr[k++] = Vec2d(w-1, h/2) - Vec2d(w-1, h/8) + Vec2d(w-1, h/4/N*i);
538
541
}
@@ -553,10 +556,14 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input
553
556
double minx = DBL_MAX, miny = DBL_MAX, maxx = -DBL_MAX, maxy = -DBL_MAX;
554
557
for (size_t i = 0 ; i < points.total (); ++i)
555
558
{
556
- miny = std::min (miny, pptr[i][1 ]);
557
- maxy = std::max (maxy, pptr[i][1 ]);
558
- minx = std::min (minx, pptr[i][0 ]);
559
- maxx = std::max (maxx, pptr[i][0 ]);
559
+ if (i!=1 && i!=5 ){
560
+ minx = std::min (minx, std::abs (pptr[i][0 ]-cn[0 ]));
561
+ }
562
+ if (i!=3 && i!=7 ){
563
+ miny = std::min (miny, std::abs (pptr[i][1 ]-cn[1 ]));
564
+ }
565
+ maxy = std::max (maxy, std::abs (pptr[i][1 ]-cn[1 ]));
566
+ maxx = std::max (maxx, std::abs (pptr[i][0 ]-cn[0 ]));
560
567
}
561
568
562
569
#if 0
@@ -570,13 +577,13 @@ void cv::fisheye::estimateNewCameraMatrixForUndistortRectify(InputArray K, Input
570
577
}
571
578
#endif
572
579
573
- double f1 = w * 0.5 /(cn[ 0 ] - minx);
574
- double f2 = w * 0.5 /(maxx - cn[ 0 ] );
575
- double f3 = h * 0.5 * aspect_ratio/(cn[ 1 ] - miny);
576
- double f4 = h * 0.5 * aspect_ratio/(maxy - cn[ 1 ] );
580
+ double f1 = w * 0.5 /(minx);
581
+ double f2 = w * 0.5 /(maxx);
582
+ double f3 = h * 0.5 * aspect_ratio/(miny);
583
+ double f4 = h * 0.5 * aspect_ratio/(maxy);
577
584
578
- double fmin = std::min (f1, std::min (f2, std::min (f3, f4)) );
579
- double fmax = std::max (f1, std::max ( f2, std::max (f3, f4)) );
585
+ double fmax = std::max (f1, f3 );
586
+ double fmin = std::min ( f2, f4 );
580
587
581
588
double f = balance * fmin + (1.0 - balance) * fmax;
582
589
f *= fov_scale > 0 ? 1.0 /fov_scale : 1.0 ;
0 commit comments