8000 calibrateCameraFromFrames throws · LumiGuide/haskell-opencv@8872140 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 8872140

Browse files
committed
calibrateCameraFromFrames throws
Also removed debug output
1 parent 34aa52a commit 8872140

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

opencv-extra/src/OpenCV/Extra/ArUco.hs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ module OpenCV.Extra.ArUco
3131
, drawEstimatedPose
3232
) where
3333

34+
import "opencv" OpenCV.Internal.Exception
3435
import "base" Control.Monad (guard)
3536
import "primitive" Control.Monad.Primitive
3637
import "base" Data.Monoid ((<>))
38+
import qualified "vector" Data.Vector.Storable as SV
3739
import "base" Foreign.C
3840
import "base" Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
3941
import "base" Foreign.Marshal.Alloc
@@ -45,13 +47,13 @@ import qualified "inline-c" Language.C.Inline.Unsafe as CU
4547
import "linear" Linear
4648
import "opencv" OpenCV
4749
import "opencv" OpenCV.Core.Types.Vec (Vec3d)
50+
import "opencv" OpenCV.Exception
4851
import "this" OpenCV.Extra.Internal.C.Inline ( openCvExtraCtx )
4952
import "this" OpenCV.Extra.Internal.C.Types
5053
import "opencv" OpenCV.Internal
5154
import "opencv" OpenCV.Internal.C.Types
5255
import "opencv" OpenCV.Internal.Core.Types.Mat
5356
import "base" System.IO.Unsafe
54-
import qualified "vector" Data.Vector.Storable as SV
5557

5658
--------------------------------------------------------------------------------
5759
C.context openCvExtraCtx
@@ -274,19 +276,21 @@ calibrateCameraFromFrames
274276
-> Int
275277
-> Int
276278
-> [(ArUcoMarkers, ChArUcoMarkers)]
277-
-> (Matx33d, Matx51d)
279+
-> CvExcept (Matx33d, Matx51d)
278280
calibrateCameraFromFrames board width height frames =
279-
unsafePerformIO $ do
281+
unsafeWrapException $ do
280282
cameraMatrix <- newMatx33d 0 0 0 0 0 0 0 0 0
281283
distCoeffs <- newMatx51d 0 0 0 0 0
282-
withPtr cameraMatrix $ \cameraMatrixPtr ->
284+
handleCvException (pure (cameraMatrix, distCoeffs)) $
285+
withPtr cameraMatrix $ \cameraMatrixPtr ->
283286
withPtr distCoeffs $ \distCoeffsPtr ->
284287
withPtr board $ \c'board ->
285288
withPtrs (map (arucoIds . fst) frames) $ \c'allIds ->
286289
withPtrs (map (arucoCorners . fst) frames) $ \c'allCorners ->
287290
withPtrs (fmap (charucoCorners . snd) frames) $ \c'allCharucoCorners ->
288291
withPtrs (fmap (charucoIds . snd) frames) $ \c'allCharucoIds -> do
289-
[C.block| void {
292+
293+
[cvExcept|
290294
vector< vector<Point2f> > allCorners;
291295
for(auto i = 0; i < $vec-len:c'allCorners; i++) {
292296
auto & corners =
@@ -341,11 +345,7 @@ calibrateCameraFromFrames board width height frames =
341345
noArray(),
342346
noArray(),
343347
perViewErrors);
344-
345-
cout << "Reprojection errors (per frame): " << endl;
346-
cout << perViewErrors << endl;
347-
}|]
348-
return (cameraMatrix, distCoeffs)
348+
|]
349349
where
350350
c'width = fromIntegral width
351351
c'height = fromIntegral height

0 commit comments

Comments
 (0)
0