SharpCV icon indicating copy to clipboard operation
SharpCV copied to clipboard

Please provide F# examples

Open OlegAlexander opened this issue 2 years ago • 2 comments

Hello and thank you for creating SharpCV. Could you please provide a few F# examples in the readme? Because I'm having trouble getting SharpCV to work in F#. Thank you!

OlegAlexander avatar May 15 '22 02:05 OlegAlexander

This code type-checks:

open SharpCV
open type SharpCV.Binding

let arr =
    let m =
        [   [ 0.; 1.; 0. ]
            [ -1.; 5.; -1. ]
            [ 0.; -1.; 0.]
        ] |> array2D
    new Tensorflow.NumPy.NDArray(m)
let mat = new Mat(arr)

charlesroddie avatar May 15 '22 08:05 charlesroddie

@charlesroddie Yes! It's working for me now. open type is what I was missing.

Here's my working example:

#r "nuget: SharpCV"
#r "nuget: OpenCvSharp4.runtime.win"
open SharpCV
open type SharpCV.Binding

let img = cv2.imread("image.png")
let imgSmall = cv2.resize(img, (0,0), 0.5, 0.5, InterpolationFlags.INTER_CUBIC)
cv2.imshow("imgSmall", imgSmall)
cv2.waitKey(0);

Now a related question: How do I display a cv image in a .NET Interactive Notebook in VS Code? Thanks!

OlegAlexander avatar May 15 '22 21:05 OlegAlexander