]> rtime.felk.cvut.cz Git - opencv.git/commitdiff
Docstrings
authorjamesbowman <jamesbowman@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Tue, 15 Sep 2009 23:38:40 +0000 (23:38 +0000)
committerjamesbowman <jamesbowman@73c94f0f-984f-4a5f-82bc-2d8db8d8ee08>
Tue, 15 Sep 2009 23:38:40 +0000 (23:38 +0000)
git-svn-id: https://code.ros.org/svn/opencv/trunk@2132 73c94f0f-984f-4a5f-82bc-2d8db8d8ee08

opencv/interfaces/python/cv.cpp
opencv/interfaces/python/gen.py

index a52c62aa249d25af961231681e127ba699f7b064..3a7e159324c6c46ab284c14e576649a9aad26920 100644 (file)
@@ -3284,35 +3284,35 @@ static PyObject *pycvGetMinMaxHistValue(PyObject *self, PyObject *args, PyObject
 
 static PyMethodDef methods[] = {
 
-  {"CreateHist", pycvCreateHist, METH_VARARGS},
-  {"CreateImage", pycvCreateImage, METH_VARARGS},
-  {"CreateImageHeader", pycvCreateImageHeader, METH_VARARGS},
-  {"CreateMat", pycvCreateMat, METH_VARARGS},
-  {"CreateMatHeader", pycvCreateMatHeader, METH_VARARGS},
-  {"CreateMatND", pycvCreateMatND, METH_VARARGS},
-  {"CreateMatNDHeader", pycvCreateMatNDHeader, METH_VARARGS},
-  {"CreateMemStorage", pycvCreateMemStorage, METH_VARARGS},
-  {"FindContours", (PyCFunction)pycvFindContours, METH_KEYWORDS},
-  {"ApproxPoly", (PyCFunction)pycvApproxPoly, METH_KEYWORDS},
-  {"CreateData", pycvCreateData, METH_VARARGS},
-  {"GetDims", pycvGetDims, METH_VARARGS},
-  {"GetImage", pycvGetImage, METH_VARARGS},
-  {"GetMat", pycvGetMat, METH_VARARGS},
-  {"Reshape", pycvReshape, METH_VARARGS},
-  {"InitLineIterator", pycvInitLineIterator, METH_VARARGS},
-  {"LoadImage", (PyCFunction)pycvLoadImage, METH_KEYWORDS},
-  {"SetData", pycvSetData, METH_VARARGS},
-  {"SetMouseCallback", (PyCFunction)pycvSetMouseCallback, METH_KEYWORDS},
-  {"CreateTrackbar", (PyCFunction)pycvCreateTrackbar, METH_KEYWORDS},
-  {"CalcEMD2", (PyCFunction)pycvCalcEMD2, METH_KEYWORDS},
-  {"FindChessboardCorners", (PyCFunction)pycvFindChessboardCorners, METH_KEYWORDS},
-  {"FitLine", (PyCFunction)pycvFitLine, METH_KEYWORDS},
-  {"Subdiv2DLocate", pycvSubdiv2DLocate, METH_VARARGS},
-  {"CalcOpticalFlowPyrLK", pycvCalcOpticalFlowPyrLK, METH_VARARGS},
-  {"ClipLine", (PyCFunction)pycvClipLine, METH_KEYWORDS},
-  {"GetHuMoments", (PyCFunction)pycvGetHuMoments, METH_KEYWORDS},
-  {"GetMinMaxHistValue", (PyCFunction)pycvGetMinMaxHistValue, METH_KEYWORDS},
-  {"WaitKey", (PyCFunction)pycvWaitKey, METH_KEYWORDS},
+  {"CreateHist", pycvCreateHist, METH_VARARGS, "CreateHist(dims, type, ranges, uniform = 1) -> hist"},
+  {"CreateImage", pycvCreateImage, METH_VARARGS, "CreateImage(size, depth, channels) -> image"},
+  {"CreateImageHeader", pycvCreateImageHeader, METH_VARARGS, "CreateImageHeader(size, depth, channels) -> image"},
+  {"CreateMat", pycvCreateMat, METH_VARARGS, "CreateMat(row, cols, type) -> mat"},
+  {"CreateMatHeader", pycvCreateMatHeader, METH_VARARGS, "CreateMatHeader(rows, cols, type) -> mat"},
+  {"CreateMatND", pycvCreateMatND, METH_VARARGS, "CreateMatND(dims, type) -> matnd"},
+  {"CreateMatNDHeader", pycvCreateMatNDHeader, METH_VARARGS, "CreateMatNDHeader(dims, type) -> matnd"},
+  {"CreateMemStorage", pycvCreateMemStorage, METH_VARARGS, "CreateMemStorage(block_size) -> memstorage"},
+  {"FindContours", (PyCFunction)pycvFindContours, METH_KEYWORDS, "FindContours(image, storage, mode=CV_RETR_LIST, method=CV_CHAIN_APPROX_SIMPLE, offset=(0, 0)) -> cvseq"},
+  {"ApproxPoly", (PyCFunction)pycvApproxPoly, METH_KEYWORDS, "ApproxPoly(src_seq, storage, method, parameter=0, parameter2=0) -> None"},
+  {"CreateData", pycvCreateData, METH_VARARGS, "CreateData(arr) -> None"},
+  {"GetDims", pycvGetDims, METH_VARARGS, "GetDims(arr) -> dims"},
+  {"GetImage", pycvGetImage, METH_VARARGS, "GetImage(cvmat) -> image"},
+  {"GetMat", pycvGetMat, METH_VARARGS, "GetMat(image) -> cvmat"},
+  {"Reshape", pycvReshape, METH_VARARGS, "Reshape(arr, new_cn, new_rows=0) -> cvmat"},
+  {"InitLineIterator", pycvInitLineIterator, METH_VARARGS, "InitLineIterator(image, pt1, pt2, connectivity=8, left_to_right=0) -> None"},
+  {"LoadImage", (PyCFunction)pycvLoadImage, METH_KEYWORDS, "LoadImage(filename, iscolor=CV_LOAD_IMAGE_COLOR)"},
+  {"SetData", pycvSetData, METH_VARARGS, "SetData(arr, data, step)"},
+  {"SetMouseCallback", (PyCFunction)pycvSetMouseCallback, METH_KEYWORDS, "SetMouseCallback(window_name, on_mouse, param) -> None"},
+  {"CreateTrackbar", (PyCFunction)pycvCreateTrackbar, METH_KEYWORDS, "CreateTrackbar(trackbar_name, window_name, value, count, on_change) -> None"},
+  {"CalcEMD2", (PyCFunction)pycvCalcEMD2, METH_KEYWORDS, "CalcEMD2(signature1, signature2, distance_type, distance_func = None, cost_matrix=None, flow=None, lower_bound=None, userdata = None) -> float"},
+  {"FindChessboardCorners", (PyCFunction)pycvFindChessboardCorners, METH_KEYWORDS, "FindChessboardCorners(image, pattern_size, flags=CV_CALIB_CB_ADAPTIVE_THRESH) -> success,corners"},
+  {"FitLine", (PyCFunction)pycvFitLine, METH_KEYWORDS, "FitLine(points, dist_type, param, reps, aeps) -> line"},
+  {"Subdiv2DLocate", pycvSubdiv2DLocate, METH_VARARGS, "Subdiv2DLocate(subdiv, pt) -> (loc, where)"},
+  {"CalcOpticalFlowPyrLK", pycvCalcOpticalFlowPyrLK, METH_VARARGS, "CalcOpticalFlowPyrLK(prev, curr, prev_pyr, curr_pyr, prev_features, CvSize win_size, int level, criteria, flags, guesses = None) -> (curr_features, status, track_error)"},
+  {"ClipLine", (PyCFunction)pycvClipLine, METH_KEYWORDS, "ClipLine(img, pt1, pt2) -> (clipped_pt1, clipped_pt2)"},
+  {"GetHuMoments", (PyCFunction)pycvGetHuMoments, METH_KEYWORDS, "GetHuMoments(cvmoments) -> (h1, h2, h3, h4, h5, h5, h7)"},
+  {"GetMinMaxHistValue", (PyCFunction)pycvGetMinMaxHistValue, METH_KEYWORDS, "GetMinMaxHistValue(hist) -> min_val,max_val,min_loc,max_loc"},
+  {"WaitKey", (PyCFunction)pycvWaitKey, METH_KEYWORDS, "WaitKey(delay=0) -> int"},
 
   {"temp_test", temp_test, METH_VARARGS},
 
index 562f7fdea21b2b9a22e0e566179c1d08f807f77a..096b40006b471ed03ea299b5459fd2940b8ee4ed 100644 (file)
@@ -96,9 +96,16 @@ conversion_types = [
 def safename(s):
   return s.replace('*', 'PTR').replace('[', '_').replace(']', '_')
 
+def has_optional(al):
+    """ return true if any argument is optional """
+    return any([a.init for a in al])
+
 def gen(name, args, ty):
   yield ""
-  yield "static PyObject *pycv%s(PyObject *self, PyObject *args, PyObject *kw)" % cname(name)
+  if has_optional(args):
+      yield "static PyObject *pycv%s(PyObject *self, PyObject *args, PyObject *kw)" % cname(name) 
+  else:
+      yield "static PyObject *pycv%s(PyObject *self, PyObject *args)" % cname(name)
   yield "{"
 
   destinations = []
@@ -261,7 +268,26 @@ gen_c = [ open("generated%d.i" % i, "w") for i in range(3) ]
 
 print "Generated %d functions" % len(api)
 for nm,args,ty in sorted(api):
-  entry = '{"%%s", (PyCFunction)pycv%s, METH_KEYWORDS},' % (cname(nm))
+
+  # Figure out docstring into ds_*
+  ds_args = []
+  mandatory = [a.nm for a in args if not ('O' in a.flags) and not a.init]
+  optional = [a.nm for a in args if not ('O' in a.flags) and a.init]
+  ds_args = ", ".join(mandatory)
+  def o2s(o):
+    if o == []:
+        return ""
+    else:
+        return ' [, %s%s]' % (o[0], o2s(o[1:]))
+  ds_args += o2s(optional)
+
+  ds = "%s(%s) -> %s" % (nm, ds_args, str(ty))
+  print ds
+
+  if has_optional(args):
+      entry = '{"%%s", (PyCFunction)pycv%s, METH_KEYWORDS, "%s"},' % (cname(nm), ds)
+  else:
+      entry = '{"%%s", pycv%s, METH_VARARGS, "%s"},' % (cname(nm), ds)
   print >>gen_c[1], entry % (nm)
   if nm.startswith('CV_'):
     print >>gen_c[1], entry % (nm[3:])