LumiGuide / haskell-opencv

Haskell binding to OpenCV-3.x
Other
154 stars 44 forks source link

Add cv::flip and cv::transpose bindings #83

Closed FPtje closed 7 years ago

FPtje commented 7 years ago

They're simple, yet very useful operations. They would fit well in OpenCV.Core.ArrayOps

Example implementation:

flipMat
    :: CV.Mat shape channels depth
    -> Int32
    -> CV.Mat shape channels depth
flipMat src flipCode = unsafePerformIO $ do
    dst <- newEmptyMat
    CV.withPtr dst $ \dstPtr ->
      CV.withPtr src $ \srcPtr ->
        [C.block| void {
          cv::flip(*$(Mat * srcPtr), *$(Mat * dstPtr), $(int32_t flipCode));
        }|]
    pure $ unsafeCoerceMat dst

transposeMat
    :: CV.Mat ('S '[height, width]) channels depth
    -> CV.Mat ('S '[width, height]) channels depth
transposeMat src = unsafePerformIO $ do
    dst <- newEmptyMat
    CV.withPtr dst $ \dstPtr ->
      CV.withPtr src $ \srcPtr ->
        [C.block| void {
          cv::transpose(*$(Mat * srcPtr), *$(Mat * dstPtr));
        }|]
    pure $ unsafeCoerceMat dst
basvandijk commented 7 years ago

I renamed flipMat to matFlip and transposeMat to matTranspose to be consistent with the naming scheme in OpenCV.Core.ArrayOps.

I also constrained the type of flipMat to work only on 2D matrices.

Lastly I added some examples.