@@ -228,7 +228,7 @@ public void CalibrateCameraByMat()
228228 Assert . Contains ( distCoeffValues , d => Math . Abs ( d ) > 1e-20 ) ;
229229 }
230230
231- [ Fact ( Skip = "OpenCV 5: fisheye::calibrate throws an internal size-mismatch error. See https://github.com/shimat/opencvsharp/issues/1906" ) ]
231+ [ Fact ]
232232 public void FishEyeCalibrate ( )
233233 {
234234 var patternSize = new Size ( 10 , 7 ) ;
@@ -255,6 +255,51 @@ public void FishEyeCalibrate()
255255 Assert . NotEmpty ( translationVectors ) ;
256256 }
257257
258+ [ Fact ]
259+ public void FishEyeCalibrateWithNonContinuousPoints ( )
260+ {
261+ var patternSize = new Size ( 10 , 7 ) ;
262+
263+ using var image = LoadImage ( "calibration/00.jpg" ) ;
264+ using var corners = new Mat < Point2f > ( ) ;
265+ Cv2 . FindChessboardCorners ( image , patternSize , corners ) ;
266+
267+ var objectPointsArray = Create3DChessboardCorners ( patternSize , 1.0f ) . ToArray ( ) ;
268+ var imagePointsArray = corners . ToArray ( ) ;
269+
270+ // Build each per-view points Mat as column 0 of a wider (Nx2) Mat, so it is a
271+ // non-continuous view. Regression test for the toRow() workaround in
272+ // calib_fisheye_calibrate, which used to call reshape() on such a Mat directly
273+ // (reshape requires a continuous Mat).
274+ using var objectPointsWide = new Mat ( objectPointsArray . Length , 2 , MatType . CV_32FC3 ) ;
275+ using var imagePointsWide = new Mat ( imagePointsArray . Length , 2 , MatType . CV_32FC2 ) ;
276+ for ( var i = 0 ; i < objectPointsArray . Length ; i ++ )
277+ {
278+ objectPointsWide . Set ( i , 0 , objectPointsArray [ i ] ) ;
279+ objectPointsWide . Set ( i , 1 , objectPointsArray [ i ] ) ;
280+ }
281+ for ( var i = 0 ; i < imagePointsArray . Length ; i ++ )
282+ {
283+ imagePointsWide . Set ( i , 0 , imagePointsArray [ i ] ) ;
284+ imagePointsWide . Set ( i , 1 , imagePointsArray [ i ] ) ;
285+ }
286+
287+ using var objectPoints = objectPointsWide . Col ( 0 ) ;
288+ using var imagePoints = imagePointsWide . Col ( 0 ) ;
289+ Assert . False ( objectPoints . IsContinuous ( ) ) ;
290+ Assert . False ( imagePoints . IsContinuous ( ) ) ;
291+
292+ using var cameraMatrix = Mat . EyeMat ( 3 , 3 , MatType . CV_64FC1 ) ;
293+ using var distCoeffs = new Mat < double > ( ) ;
294+
295+ var rms = Cv2 . FishEye . Calibrate ( [ objectPoints ] , [ imagePoints ] , image . Size ( ) , cameraMatrix ,
296+ distCoeffs , out var rotationVectors , out var translationVectors ) ;
297+
298+ Assert . True ( rms > 8 , $ "rms = { rms } ") ;
299+ Assert . NotEmpty ( rotationVectors ) ;
300+ Assert . NotEmpty ( translationVectors ) ;
301+ }
302+
258303 /// <summary>
259304 /// https://stackoverflow.com/questions/25244603/opencvs-projectpoints-function
260305 /// </summary>
0 commit comments