@@ -31,9 +31,11 @@ module OpenCV.Extra.ArUco
31
31
, drawEstimatedPose
32
32
) where
33
33
34
+ import "opencv" OpenCV.Internal.Exception
34
35
import "base" Control.Monad (guard )
35
36
import "primitive" Control.Monad.Primitive
36
37
import "base" Data.Monoid ((<>) )
38
+ import qualified "vector" Data.Vector.Storable as SV
37
39
import "base" Foreign.C
38
40
import "base" Foreign.ForeignPtr (ForeignPtr , withForeignPtr )
39
41
import "base" Foreign.Marshal.Alloc
@@ -45,13 +47,13 @@ import qualified "inline-c" Language.C.Inline.Unsafe as CU
45
47
import "linear" Linear
46
48
import "opencv" OpenCV
47
49
import "opencv" OpenCV.Core.Types.Vec (Vec3d )
50
+ import "opencv" OpenCV.Exception
48
51
import "this" OpenCV.Extra.Internal.C.Inline ( openCvExtraCtx )
49
52
import "this" OpenCV.Extra.Internal.C.Types
50
53
import "opencv" OpenCV.Internal
51
54
import "opencv" OpenCV.Internal.C.Types
52
55
import "opencv" OpenCV.Internal.Core.Types.Mat
53
56
import "base" System.IO.Unsafe
54
- import qualified "vector" Data.Vector.Storable as SV
55
57
56
58
--------------------------------------------------------------------------------
57
59
C. context openCvExtraCtx
@@ -274,19 +276,21 @@ calibrateCameraFromFrames
274
276
-> Int
275
277
-> Int
276
278
-> [(ArUcoMarkers , ChArUcoMarkers )]
277
- -> (Matx33d , Matx51d )
279
+ -> CvExcept (Matx33d , Matx51d )
278
280
calibrateCameraFromFrames board width height frames =
279
- unsafePerformIO $ do
281
+ unsafeWrapException $ do
280
282
cameraMatrix <- newMatx33d 0 0 0 0 0 0 0 0 0
281
283
distCoeffs <- newMatx51d 0 0 0 0 0
282
- withPtr cameraMatrix $ \ cameraMatrixPtr ->
284
+ handleCvException (pure (cameraMatrix, distCoeffs)) $
285
+ withPtr cameraMatrix $ \ cameraMatrixPtr ->
283
286
withPtr distCoeffs $ \ distCoeffsPtr ->
284
287
withPtr board $ \ c'board ->
285
288
withPtrs (map (arucoIds . fst ) frames) $ \ c'allIds ->
286
289
withPtrs (map (arucoCorners . fst ) frames) $ \ c'allCorners ->
287
290
withPtrs (fmap (charucoCorners . snd ) frames) $ \ c'allCharucoCorners ->
288
291
withPtrs (fmap (charucoIds . snd ) frames) $ \ c'allCharucoIds -> do
289
- [C. block | void {
292
+
293
+ [cvExcept |
290
294
vector< vector<Point2f> > allCorners;
291
295
for(auto i = 0; i < $vec-len:c'allCorners; i++) {
292
296
auto & corners =
@@ -341,11 +345,7 @@ calibrateCameraFromFrames board width height frames =
341
345
noArray(),
342
346
noArray(),
343
347
perViewErrors);
344
-
345
- cout << "Reprojection errors (per frame): " << endl;
346
- cout << perViewErrors << endl;
347
- }|]
348
- return (cameraMatrix, distCoeffs)
348
+ |]
349
349
where
350
350
c'width = fromIntegral width
351
351
c'height = fromIntegral height
0 commit comments