8000 Fix type of drawChArUcoBoard and add example · LumiGuide/haskell-opencv@28f88fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 28f88fa

Browse files
committed
Fix type of drawChArUcoBoard and add example
1 parent 2c5b745 commit 28f88fa

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

opencv-extra/opencv-extra.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ library
4343
, inline-c >= 0.5.5.5
4444
, inline-c-cpp >= 0.1
4545
, linear >= 1.20.4
46-
, opencv == 0.0.0
46+
, opencv >= 0.0.0.0
4747
, primitive >= 0.6.1
4848
, template-haskell >= 2.10
4949
, transformers >= 0.4.2
@@ -96,6 +96,7 @@ test-suite doc-images-opencv-extra
9696
, directory
9797
, Glob
9898
, haskell-src-exts
99+
, JuicyPixels
99100
, linear
100101
, opencv
101102
, opencv-extra

opencv-extra/opencv-extra.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
, directory
2323
, Glob
2424
, haskell-src-exts
25+
, JuicyPixels
2526
}:
2627
mkDerivation {
2728
pname = "opencv-extra";
@@ -66,6 +67,7 @@ mkDerivation {
6667
directory
6768
Glob
6869
haskell-src-exts
70+
JuicyPixels
6971
];
7072

7173
libraryPkgconfigDepends = [ opencv3 ];

opencv-extra/src/OpenCV/Extra.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module OpenCV.Extra
44
( module Extra
55
) where
66

7+
import OpenCV.Extra.ArUco as Extra
78
import OpenCV.Extra.Bgsegm as Extra
89
import OpenCV.Extra.Tracking as Extra
910
import OpenCV.Extra.XFeatures2d as Extra
1011
import OpenCV.Extra.XPhoto as Extra
1112
import OpenCV.Extra.XPhoto.WhiteBalancer as Extra
12-

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

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import "opencv" OpenCV.Internal.Exception
3535
import "base" Control.Monad (guard)
3636
import "primitive" Control.Monad.Primitive
3737
import "base" Data.Monoid ((<>))
38+
import "base" Data.Word ( Word8 )
3839
import qualified "vector" Data.Vector.Storable as SV
3940
import "base" Foreign.C
4041
import "base" Foreign.ForeignPtr (ForeignPtr, withForeignPtr)
@@ -47,7 +48,6 @@ import qualified "inline-c" Language.C.Inline.Unsafe as CU
4748
import "linear" Linear
4849
import "opencv" OpenCV
4950
import "opencv" OpenCV.Core.Types.Vec (Vec3d)
50-
import "opencv" OpenCV.Exception
5151
import "this" OpenCV.Extra.Internal.C.Inline ( openCvExtraCtx )
5252
import "this" OpenCV.Extra.Internal.C.Types
5353
import "opencv" OpenCV.Internal
@@ -490,19 +490,45 @@ getPredefinedDictionary name =
490490

491491
{-| Draw a ChArUco board, ready to be printed and used for calibration/marke
492492
detection.
493+
494+
Example:
495+
496+
@
497+
drawChArUcoBoardImg
498+
:: forall (w :: Nat) (h :: Nat)
499+
. (w ~ 500, h ~ 500)
500+
=> Mat ('S '[ 'S h, 'S w]) ('S 1) ('S Word8)
501+
drawChArUcoBoardImg =
502+
drawChArUcoBoard charucoBoard (Proxy :: Proxy w) (Proxy :: Proxy h)
503+
where
504+
charucoBoard :: ChArUcoBoard
505+
charucoBoard = createChArUcoBoard 10 10 20 5 dictionary
506+
507+
dictionary :: Dictionary
508+
dictionary = getPredefinedDictionary DICT_7X7_1000
509+
@
510+
511+
<<doc/generated/examples/drawChArUcoBoardImg.png drawChArUcoBoardImg>>
493512
-}
494-
drawChArUcoBoard :: ChArUcoBoard -> Mat ('S '[h, w]) ('S 1) depth
495-
drawChArUcoBoard charucoBoard = unsafePerformIO $ do
513+
drawChArUcoBoard
514+
:: (ToInt32 w, ToInt32 h)
515+
=> ChArUcoBoard
516+
-> w -- ^ width
517+
-> h -- ^ height
518+
-> Mat ('S '[DSNat h, DSNat w]) ('S 1) ('S Word8)
519+
drawChArUcoBoard charucoBoard width height = unsafePerformIO $ do
496520
dst <- newEmptyMat
497521
withPtr charucoBoard $ \c'board ->
498522
withPtr dst $ \dstPtr ->
499523
[C.block| void {
500524
Mat & board = * $(Mat * dstPtr);
501525
Ptr<CharucoBoard> & charucoBoard = *$(Ptr_CharucoBoard * c'board);
502-
charucoBoard->draw(cv::Size(500, 500), board);
526+
charucoBoard->draw(cv::Size($(int32_t w), $(int32_t h)), board);
503527
}|]
504528
pure (unsafeCoerceMat dst)
505-
529+
where
530+
w = toInt32 width
531+
h = toInt32 height
506532

507533
--------------------------------------------------------------------------------
508534
withPtrs

0 commit comments

Comments
 (0)
0