@@ -52,19 +52,22 @@ module OpenCV.ImgProc.GeometricImgTransform
52
52
, linearPolar
53
53
, logPolar
54
54
, getPerspectiveTransform
55
+ , getAffineTransform
55
56
, getRotationMatrix2D
56
57
, remap
57
58
, undistort
58
59
) where
59
60
60
61
import "base" Data.Int ( Int32 )
62
+ import "base" Data.Foldable
61
63
import "base" Foreign.C.Types ( CFloat , CDouble )
62
64
import "base" System.IO.Unsafe ( unsafePerformIO )
63
65
import qualified Data.Vector as V
64
66
import qualified "inline-c" Language.C.Inline as C
65
67
import qualified "inline-c" Language.C.Inline.Unsafe as CU
66
68
import qualified "inline-c-cpp" Language.C.Inline.Cpp as C
67
69
import "linear" Linear.V2 ( V2 (.. ) )
70
+ import "linear" Linear.V3 ( V3 (.. ) )
68
71
import "linear" Linear.Vector ( zero )
69
72
import "mtl" Control.Monad.Error.Class ( MonadError )
70
73
import "this" OpenCV.Core.Types
@@ -458,6 +461,30 @@ getPerspectiveTransform srcPts dstPts = unsafeCoerceMat $ unsafePerformIO $
458
461
);
459
462
}|]
460
463
464
+ {- | Calculates an affine transformation matrix for 2D affine transform
465
+
466
+ <http://docs.opencv.org/3.0-last-rst/modules/imgproc/doc/geometric_transformations.html#getaffinetransform OpenCV Sphinx doc>
467
+ -}
468
+ getAffineTransform
469
+ :: forall m point2 . (MonadError CvException m , IsPoint2 point2 CFloat )
470
+ => V3 (point2 CFloat ) -- ^ Points representing vertices in source image
471
+ -> V3 (point2 CFloat ) -- ^ Points representing vertices in destination image
472
+ -> m (Mat (ShapeT [2 , 3 ]) ('S 1 ) ('S Double )) -- ^ The output affine transformation, 2x3 floating-point-matrix.
473
+ getAffineTransform srcPts dstPts = unsafeWrapException $ do
474
+ result <- newEmptyMat
475
+ handleCvException (pure $ unsafeCoerceMat result) $
476
+ withPtr result $ \ resultPtr ->
477
+ withArrayPtr (v3ToVector srcPts) $ \ srcPtsPtr ->
478
+ withArrayPtr (v3ToVector dstPts) $ \ dstPtsPtr ->
479
+ [cvExcept |
480
+ *$(Mat * resultPtr) =
481
+ cv::getAffineTransform($(Point2f * srcPtsPtr), $(Point2f * dstPtsPtr));
482
+ }|]
483
+ where
484
+ v3ToVector :: V3 (point2 CFloat ) -> V. Vector Point2f
485
+ v3ToVector = V. map toPoint . V. fromList . toList
486
+
487
+
461
488
{- | Calculates an affine matrix of 2D rotation
462
489
463
490
<http://docs.opencv.org/3.0-last-rst/modules/imgproc/doc/geometric_transformations.html#getrotationmatrix2d OpenCV Sphinx doc>
0 commit comments