dom96 / nim-opencv

Nim OpenCV wrapper
MIT License
55 stars 5 forks source link

[RFC] A wrapper that adds Python-like procs #10

Open jlp765 opened 5 years ago

jlp765 commented 5 years ago

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:

dom96 commented 5 years ago

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