Since OpenCV provide C++ API,and the Mathemtica provide so many method to connect C++. I think we can call it with our Mathematica. The OpenCV provide many powerfull function for image-processing. It can help us a lot.

As the Szabolcs here,Mathematica provide such directory,maybe contain a ready-made link in

FileNameJoin[{$TopDirectory, "SystemFiles", "Links", "OpenCVLink"}]

And I can use some function with one argument,such as OpenCVLinkPrivate$Dilation

<< OpenCVLink`
img = ExampleData[{"TestImage", "Lena"}];
OpenCVLink`Private`$Dilation[img, 2]

But I don't know how to use other function such as OpenCVLink`Private`$HoughCircles or stitcher.stitch in opencv_stitching310.dll for this question. And I don't think this is a right way to call it since it include a Private`.Can anyone can tell me more?

  • $\begingroup$ It doesn't seem like there are any public functions there. But here's a way to find all of the LibraryFunction: Pick[Names["OpenCVLink`Private`*"], MatchQ[{_ :> _LibraryFunction}] /@ ToExpression[Names["OpenCVLink`Private`*"], StandardForm, OwnValues] ]. This listing seems reasonable. $\endgroup$
    – b3m2a1
    Commented Sep 5, 2017 at 13:39
  • $\begingroup$ @b3m2a1 Thanks,but I think since the context contain Private.I think it is not a open solution.. $\endgroup$
    – yode
    Commented Sep 5, 2017 at 13:58
  • $\begingroup$ The private simply means it's free to change at whim. But that's the case with all the undocumented functionality we use. Core OpenCVLink is distributed in the Links directory, not as a paclet, so it should be stable at least within versions and, probably, between point releases. $\endgroup$
    – b3m2a1
    Commented Sep 5, 2017 at 14:00
  • 1
    $\begingroup$ From Mathematica, you would only be able to call the library functions as listed in InitOpenCVLink as pointed out by b3m2a1. There is no LibraryLink interface implemented for every single OpenCV function. As for how to call $HoughCircles, it shouldn't be difficult to figure out from the OpenCV documentation what is the meaning of the four real and two integer parameters: dp, minDist, param1, param2, minRadius and maxRadius in that order. $\endgroup$
    – ilian
    Commented Sep 6, 2017 at 22:56
  • 1
    $\begingroup$ @b3m2a1 The fact that it is located under Links does not mean it cannot be paclet-updated if desired -- the paclet manager would simply use the highest version available, which could be a downloaded one. $\endgroup$
    – ilian
    Commented Sep 7, 2017 at 3:00

1 Answer 1


Here's an example of something you can do with this. Not having seen ilian's comment, all I did was accessed the private LibraryFunction, looked at its parameters, looked at the docs and guessed from there at the parameters.

  dp : _?NumericQ : 5,
  minDist : _?NumericQ | Scaled[_?NumericQ] : Scaled[.25],
  cannyThreshold : _?NumericQ : 100,
  accumulatorThreshold : _?NumericQ : 100,
  minRadius : _Integer : 0,
  maxRadius : _Integer : 0
  ] :=
       ColorConvert[img, "Grayscale"],
     Scaled[i_] :> ImageDimensions[img][[2]]*i
    cannyThreshold, accumulatorThreshold,
    minRadius, maxRadius

  ] :=
 With[{hCs = houghCircles[img, houghParams]},
    Inset[Image[img, ImageSize -> ImageDimensions[img]], Center, 
     Center, ImageDimensions[img]],
       {Green, Circle[Most[#], 3]},
       {Red, Circle[Most[#], Last[#]]}
       } & /@ hCs
   ImageSize -> ImageDimensions[img],
   PlotRange -> Thread[{0, ImageDimensions[img]}],
   AspectRatio -> Full

Beware that I'm pretty sure my annotation function is garbage though. I just did this to see how it worked:

img = Import["https://i.sstatic.net/qV2Hz.jpg"];


garbage output

I'm sure with a bit more doc reading it could be made not garbage though

  • 1
    $\begingroup$ garbage indeed.Sorry for laugh about that result image. :) $\endgroup$
    – yode
    Commented Sep 16, 2017 at 8:29
  • $\begingroup$ @yode I'm not offended at all. I think that function took a total of 5 minutes to spit out, including docs reading. $\endgroup$
    – b3m2a1
    Commented Sep 16, 2017 at 8:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.