dom96 / nim-opencv

Nim OpenCV wrapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[RFC] A wrapper that adds Python-like procs

jlp765 opened this issue · comments

Background
When using open-cv in Python, a lot of the base functions are "translated" into functions that return the result rather than the result being passed in/out via a parameter, i.e.

void cv::normalize (InputArray src,
  InputOutputArray dst,
  double alpha = 1,
  double beta = 0,
  int norm_type = NORM_L2,
  int dtype = -1,
  InputArray mask = noArray()
  )

translates to

dst = cv.normalize(src, dst[, alpha[, beta[, norm_type[, dtype[, mask]]]]])

Most (but not all) translations have the destination being the same dimensions as the source, so in Nim the translating function for above would be like

proc normalize*(src: ImgPtr; 
                a: cdouble = 1.0;
                b: cdouble = 0.0; 
                normType: cint = 2;
                mask: ImgPtr = nil): ImgPtr =
  result = createImage(size(src.width, src.height), src.depth, src.nChannels)
  normalize(src, result, a, b, normType, mask)

Note: the dst parameter in Python is usually passed in as None, so it is removed in the Nim example I provided.

Proposal
Have a high-level library which is the "user-friendly" library that provides the ease of use and whose procs provide more readable python-like Nim code for the user.

Some questions regarding the high level library:

  • is it a three headed medusa or does it include highgui, core and imgproc all in one place?
  • does it export the three underlying libraries so users don't have to also include the low level libraries if the low-level types and procs are required?
  • use templates/macros which makes the library code less readable and documentation more difficult?

feel free to write this, I think it would work best as a separate package.