From 59e2afe4d291862dad355a2ca8ad7282828cd98f Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 25 Nov 2010 23:16:32 +0000 Subject: [PATCH] fixed the ordering of parameters in PyArg_ParseTupleAndKeywords, added correct Ptr::delete_obj() (ticket #406) --- .../imgproc/include/opencv2/imgproc/imgproc.hpp | 16 ++++++++-------- modules/ml/include/opencv2/ml/ml.hpp | 3 ++- modules/ml/src/tree.cpp | 13 +++++++++---- modules/python/gen2.py | 16 ++++++++-------- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/modules/imgproc/include/opencv2/imgproc/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc/imgproc.hpp index 180ba9aa2..f22aa8ba6 100644 --- a/modules/imgproc/include/opencv2/imgproc/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc/imgproc.hpp @@ -383,7 +383,7 @@ CV_EXPORTS_W void copyMakeBorder( const Mat& src, CV_OUT Mat& dst, //! smooths the image using median filter. CV_EXPORTS_W void medianBlur( const Mat& src, CV_OUT Mat& dst, int ksize ); //! smooths the image using Gaussian filter. -CV_EXPORTS_W void GaussianBlur( const Mat& src, CV_OUT Mat& dst, Size ksize, +CV_EXPORTS_AS(gaussianBlur) void GaussianBlur( const Mat& src, CV_OUT Mat& dst, Size ksize, double sigma1, double sigma2=0, int borderType=BORDER_DEFAULT ); //! smooths the image using bilateral filter @@ -412,23 +412,23 @@ CV_EXPORTS_W void sepFilter2D( const Mat& src, CV_OUT Mat& dst, int ddepth, double delta=0, int borderType=BORDER_DEFAULT ); //! applies generalized Sobel operator to the image -CV_EXPORTS_W void Sobel( const Mat& src, CV_OUT Mat& dst, int ddepth, +CV_EXPORTS_AS(sobel) void Sobel( const Mat& src, CV_OUT Mat& dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, double delta=0, int borderType=BORDER_DEFAULT ); //! applies the vertical or horizontal Scharr operator to the image -CV_EXPORTS_W void Scharr( const Mat& src, CV_OUT Mat& dst, int ddepth, +CV_EXPORTS_AS(scharr) void Scharr( const Mat& src, CV_OUT Mat& dst, int ddepth, int dx, int dy, double scale=1, double delta=0, int borderType=BORDER_DEFAULT ); //! applies Laplacian operator to the image -CV_EXPORTS_W void Laplacian( const Mat& src, CV_OUT Mat& dst, int ddepth, +CV_EXPORTS_AS(laplacian) void Laplacian( const Mat& src, CV_OUT Mat& dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT ); //! applies Canny edge detector and produces the edge map. -CV_EXPORTS_W void Canny( const Mat& image, CV_OUT Mat& edges, +CV_EXPORTS_AS(canny) void Canny( const Mat& image, CV_OUT Mat& edges, double threshold1, double threshold2, int apertureSize=3, bool L2gradient=false ); @@ -463,17 +463,17 @@ CV_EXPORTS_W void goodFeaturesToTrack( const Mat& image, CV_OUT vector& bool useHarrisDetector=false, double k=0.04 ); //! finds lines in the black-n-white image using the standard or pyramid Hough transform -CV_EXPORTS_W void HoughLines( const Mat& image, CV_OUT vector& lines, +CV_EXPORTS_AS(houghLines) void HoughLines( const Mat& image, CV_OUT vector& lines, double rho, double theta, int threshold, double srn=0, double stn=0 ); //! finds line segments in the black-n-white image using probabalistic Hough transform -CV_EXPORTS_W void HoughLinesP( Mat& image, CV_OUT vector& lines, +CV_EXPORTS_AS(houghLinesP) void HoughLinesP( Mat& image, CV_OUT vector& lines, double rho, double theta, int threshold, double minLineLength=0, double maxLineGap=0 ); //! finds circles in the grayscale image using 2+1 gradient Hough transform -CV_EXPORTS_W void HoughCircles( const Mat& image, CV_OUT vector& circles, +CV_EXPORTS_AS(houghCircles) void HoughCircles( const Mat& image, CV_OUT vector& circles, int method, double dp, double minDist, double param1=100, double param2=100, int minRadius=0, int maxRadius=0 ); diff --git a/modules/ml/include/opencv2/ml/ml.hpp b/modules/ml/include/opencv2/ml/ml.hpp index 82141462d..d3cebd6f4 100644 --- a/modules/ml/include/opencv2/ml/ml.hpp +++ b/modules/ml/include/opencv2/ml/ml.hpp @@ -748,7 +748,6 @@ struct CvDTreeSplit }; }; - struct CvDTreeNode { int class_idx; @@ -2211,6 +2210,8 @@ typedef CvANN_MLP_TrainParams ANN_MLP_TrainParams; typedef CvANN_MLP NeuralNet_MLP; typedef CvGBTreesParams GradientBoostingTreeParams; typedef CvGBTrees GradientBoostingTrees; + +template<> CV_EXPORTS void Ptr::delete_obj(); } diff --git a/modules/ml/src/tree.cpp b/modules/ml/src/tree.cpp index 04a71c2db..fd7573844 100644 --- a/modules/ml/src/tree.cpp +++ b/modules/ml/src/tree.cpp @@ -1803,17 +1803,22 @@ double CvDTree::calc_node_dir( CvDTreeNode* node ) namespace cv { +template<> CV_EXPORTS void Ptr::delete_obj() +{ + fastFree(obj); +} + DTreeBestSplitFinder::DTreeBestSplitFinder( CvDTree* _tree, CvDTreeNode* _node) { tree = _tree; node = _node; splitSize = tree->get_data()->split_heap->elem_size; - bestSplit = (CvDTreeSplit*)(new char[splitSize]); + bestSplit = (CvDTreeSplit*)fastMalloc(splitSize); memset((CvDTreeSplit*)bestSplit, 0, splitSize); bestSplit->quality = -1; bestSplit->condensed_idx = INT_MIN; - split = (CvDTreeSplit*)(new char[splitSize]); + split = (CvDTreeSplit*)fastMalloc(splitSize); memset((CvDTreeSplit*)split, 0, splitSize); //haveSplit = false; } @@ -1824,9 +1829,9 @@ DTreeBestSplitFinder::DTreeBestSplitFinder( const DTreeBestSplitFinder& finder, node = finder.node; splitSize = tree->get_data()->split_heap->elem_size; - bestSplit = (CvDTreeSplit*)(new char[splitSize]); + bestSplit = (CvDTreeSplit*)fastMalloc(splitSize); memcpy((CvDTreeSplit*)(bestSplit), (const CvDTreeSplit*)finder.bestSplit, splitSize); - split = (CvDTreeSplit*)(new char[splitSize]); + split = (CvDTreeSplit*)fastMalloc(splitSize); memset((CvDTreeSplit*)split, 0, splitSize); } diff --git a/modules/python/gen2.py b/modules/python/gen2.py index 65fff48d3..e7d3f4b07 100644 --- a/modules/python/gen2.py +++ b/modules/python/gen2.py @@ -513,15 +513,15 @@ class FuncInfo(object): sys.exit(-1) amapping = simple_argtype_mapping.get(tp, (tp, "O", defval0)) - all_cargs.append(amapping) + parse_name = a.name if a.py_inputarg: if amapping[1] == "O": code_decl += " PyObject* pyobj_%s = NULL;\n" % (a.name,) - parse_arglist.append("pyobj_" + a.name) + parse_name = "pyobj_" + a.name code_cvt_list.append("pyopencv_to(pyobj_%s, %s)" % (a.name, a.name)) - else: - parse_arglist.append(a.name) - + + all_cargs.append([amapping, parse_name]) + defval = a.defval if not defval: defval = amapping[2] @@ -556,7 +556,7 @@ class FuncInfo(object): if v.args: # form the format spec for PyArg_ParseTupleAndKeywords - fmtspec = "".join([all_cargs[argno][1] for aname, argno in v.py_arglist]) + fmtspec = "".join([all_cargs[argno][0][1] for aname, argno in v.py_arglist]) if v.py_noptargs > 0: fmtspec = fmtspec[:-v.py_noptargs] + "|" + fmtspec[-v.py_noptargs:] fmtspec += ":" + fullname @@ -568,7 +568,7 @@ class FuncInfo(object): code_parse = gen_template_parse_args.substitute( kw_list = ", ".join(['"' + aname + '"' for aname, argno in v.py_arglist]), fmtspec = fmtspec, - parse_arglist = ", ".join(["&" + aname for aname in parse_arglist]), + parse_arglist = ", ".join(["&" + all_cargs[argno][1] for aname, argno in v.py_arglist]), code_cvt = " &&\n ".join(code_cvt_list)) else: code_parse = "if(PyObject_Size(args) == 0 && PyObject_Size(kw) == 0)" @@ -586,7 +586,7 @@ class FuncInfo(object): fmtspec = "N"*len(v.py_outlist) backcvt_arg_list = [] for aname, argno in v.py_outlist: - amapping = all_cargs[argno] + amapping = all_cargs[argno][0] backcvt_arg_list.append("%s(%s)" % (amapping[2], aname)) code_ret = "return Py_BuildValue(\"(%s)\", %s)" % \ (fmtspec, ", ".join(["pyopencv_from(" + aname + ")" for aname, argno in v.py_outlist]))