def transform_XXXTrainData(z): z.include_files.append( "arrayobject.h" ) # to get NumPy's flags z.include_files.append( "ndarray.hpp" ) z.mem_fun('get_vectors')._transformer_creators.extend([ FT.input_array1d('values'), FT.input_array1d('missing'), FT.input_array1d('responses')]) for t in ( 'get_cv_labels', 'get_sample_indices', 'get_cat_var_data', 'get_ord_var_data', ): z.mem_funs(t).exclude() z.add_declaration_code(''' static bp::object CLASS_NAME_get_cat_var_data(bp::object const &bpinst, CvDTreeNode* n, int vi) { CLASS_TYPE &inst = bp::extract<CLASS_TYPE &>(bpinst); int size = n->sample_count; sdcpp::ndarray result = sdcpp::simplenew_ndarray(1, &size, NPY_INT); int *in_arr = (int*)result.data(); const int *out_arr = inst.get_cat_var_data(n, vi, in_arr); if(!out_arr) return bp::object(); if(out_arr == in_arr) return result.get_obj(); result = sdcpp::new_ndarray1d(size, NPY_INT, (void *)out_arr); bp::objects::make_nurse_and_patient(result.get_obj().ptr(), bpinst.ptr()); return result.get_obj(); } static bp::object CLASS_NAME_get_cv_labels(bp::object const &bpinst, CvDTreeNode* n) { CLASS_TYPE &inst = bp::extract<CLASS_TYPE &>(bpinst); int size = n->sample_count; sdcpp::ndarray result = sdcpp::simplenew_ndarray(1, &size, NPY_INT); int *in_arr = (int*)result.data(); const int *out_arr = inst.get_cv_labels(n, in_arr); if(!out_arr) return bp::object(); if(out_arr == in_arr) return result.get_obj(); result = sdcpp::new_ndarray1d(size, NPY_INT, (void *)out_arr); bp::objects::make_nurse_and_patient(result.get_obj().ptr(), bpinst.ptr()); return result.get_obj(); } static bp::object CLASS_NAME_get_sample_indices(bp::object const &bpinst, CvDTreeNode* n) { CLASS_TYPE &inst = bp::extract<CLASS_TYPE &>(bpinst); int size = n->sample_count; sdcpp::ndarray result = sdcpp::simplenew_ndarray(1, &size, NPY_INT); int *in_arr = (int*)result.data(); const int *out_arr = inst.get_sample_indices(n, in_arr); if(!out_arr) return bp::object(); if(out_arr == in_arr) return result.get_obj(); result = sdcpp::new_ndarray1d(size, NPY_INT, (void *)out_arr); bp::objects::make_nurse_and_patient(result.get_obj().ptr(), bpinst.ptr()); return result.get_obj(); } static bp::tuple CLASS_NAME_get_ord_var_data(bp::object const &bpinst, CvDTreeNode* n, int vi) { CLASS_TYPE &inst = bp::extract<CLASS_TYPE &>(bpinst); int size = n->sample_count; std::vector<int> sample_indices(size); sdcpp::ndarray result1 = sdcpp::simplenew_ndarray(1, &size, NPY_FLOAT); sdcpp::ndarray result2 = sdcpp::simplenew_ndarray(1, &size, NPY_INT); float *in_arr1 = (float*)result1.data(); int *in_arr2 = (int*)result2.data(); const float *out_arr1; const int *out_arr2; inst.get_ord_var_data(n, vi, in_arr1, in_arr2, &out_arr1, &out_arr2, &sample_indices[0]); bp::object obj1, obj2; if(out_arr1 && out_arr1 != in_arr1) { result1 = sdcpp::new_ndarray1d(size, NPY_FLOAT, (void *)out_arr1); bp::objects::make_nurse_and_patient(result1.get_obj().ptr(), bpinst.ptr()); } if(out_arr1) obj1 = result1.get_obj(); if(out_arr2 && out_arr2 != in_arr2) { result2 = sdcpp::new_ndarray1d(size, NPY_INT, (void *)out_arr2); bp::objects::make_nurse_and_patient(result2.get_obj().ptr(), bpinst.ptr()); } if(out_arr2) obj2 = result2.get_obj(); return bp::make_tuple(obj1, obj2); } '''.replace("CLASS_NAME", z.alias).replace("CLASS_TYPE", z.pds)) z.add_registration_code('def("get_cat_var_data", &::CLASS_NAME_get_cat_var_data, (bp::arg("self"), bp::arg("n"), bp::arg("vi")))'.replace("CLASS_NAME", z.alias)) z.add_registration_code('def("get_cv_labels", &::CLASS_NAME_get_cv_labels, (bp::arg("self"), bp::arg("n")))'.replace("CLASS_NAME", z.alias)) z.add_registration_code('def("get_sample_indices", &::CLASS_NAME_get_sample_indices, (bp::arg("self"), bp::arg("n")))'.replace("CLASS_NAME", z.alias)) z.add_registration_code('def("get_ord_var_data", &::CLASS_NAME_get_ord_var_data, (bp::arg("self"), bp::arg("n"), bp::arg("vi")))'.replace("CLASS_NAME", z.alias))
''') for z in ( 'cvCalcOpticalFlowLK', 'cvCalcOpticalFlowBM', 'cvCalcOpticalFlowHS', 'cvEstimateRigidTransform', 'cvCalcOpticalFlowFarneback', 'cvUpdateMotionHistory', 'cvCalcMotionGradient', 'cvCalcGlobalOrientation', 'cvAcc', 'cvSquareAcc', 'cvMultiplyAcc', 'cvRunningAvg', ): sb.mb.free_fun(z).include() # cvCalcOpticalFlowPyrLK FT.expose_func(sb.mb.free_fun('cvCalcOpticalFlowPyrLK'), return_pointee=False, transformer_creators=[ FT.input_array1d('prev_features', 'count', output_arrays=[('curr_features','1'), ('status','1'), ('track_error','1')])]) # cvCalcAffineFlowPyrLK FT.expose_func(sb.mb.free_fun('cvCalcAffineFlowPyrLK'), return_pointee=False, transformer_creators=[ FT.input_array1d('prev_features', 'count', output_arrays=[('curr_features','1'), ('matrices','1'), ('status','1'), ('track_error','1')])]) # cvSegmentMotion FT.expose_func(sb.mb.free_fun('cvSegmentMotion'), ward_indices=(3,)) # Planar Subdivisions sb.cc.write(''' #----------------------------------------------------------------------------- # Planar Subdivisions #-----------------------------------------------------------------------------
sb.finalize_class(z) # CvDTreeNode z = sb.mb.class_('CvDTreeNode') sb.init_class(z) for t in ('parent', 'left', 'right', 'split'): FT.expose_member_as_pointee(z, t) for t in ('num_valid', 'cv_Tn', 'cv_node_risk', 'cv_node_error'): z.var(t).exclude() # members for internal use, no need to expose sb.finalize_class(z) # CvDTreeParams z = sb.mb.class_('CvDTreeParams') sb.init_class(z) FT.expose_member_as_ndarray1d(z, 'priors', 'inst.max_categories') z.constructor(lambda x: len(x.arguments) > 1)._transformer_creators.append(FT.input_array1d('_priors')) sb.finalize_class(z) # ...TrainData functions def transform_XXXTrainData(z): z.include_files.append( "arrayobject.h" ) # to get NumPy's flags z.include_files.append( "ndarray.hpp" ) z.mem_fun('get_vectors')._transformer_creators.extend([ FT.input_array1d('values'), FT.input_array1d('missing'), FT.input_array1d('responses')]) for t in ( 'get_cv_labels', 'get_sample_indices', 'get_cat_var_data', 'get_ord_var_data', ): z.mem_funs(t).exclude() z.add_declaration_code(''' static bp::object CLASS_NAME_get_cat_var_data(bp::object const &bpinst, CvDTreeNode* n, int vi) {
def beautify_func_list(func_list): func_list = [f for f in func_list if not f.ignore] # fix default values # don't remove std::vector default values, old compilers _need_ std::allocator removed for f in func_list: for arg in f.arguments: if isinstance(arg.default_value, str): repl_list = { 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >': 'std::string', 'std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >': 'std::vector<cv::Point>', 'std::vector<cv::Scalar_<double>, std::allocator<cv::Scalar_<double> > >': 'std::vector<cv::Scalar>', 'std::vector<int, std::allocator<int> >': 'std::vector<int>', 'std::vector<cv::Vec<int, 4>, std::allocator<cv::Vec<int, 4> > >': 'std::vector<cv::Vec4i>', } for z in repl_list: arg.default_value = arg.default_value.replace(z, repl_list[z]) # one-to-one function argument for f in func_list: for arg in f.arguments: if is_arg_touched(f, arg.name): continue pds = _c.unique_pds(arg.type.partial_decl_string) if pds in _c.c2cpp: f._transformer_creators.append(_FT.input_as_FixType(pds, _c.c2cpp[pds], arg.name)) elif pds in ['CvRNG *', 'CvRNG &', 'CvRNG cosnt *', 'CvRNG const &']: f._transformer_creators.append(_FT.input_asRNG(arg.name)) elif pds in ['CvFileStorage *', 'CvFileStorage const *']: f._transformer_creators.append(_FT.input_as_FileStorage(arg.name)) elif pds in ['CvFileNode *', 'CvFileNode const *']: f._transformer_creators.append(_FT.input_as_FileNode(arg.name)) elif pds in ['CvMemStorage *', 'CvMemStorage const *']: f._transformer_creators.append(_FT.input_as_MemStorage(arg.name)) elif pds in ['CvSparseMat *', 'CvSparseMat &', 'CvSparseMat const *', 'CvSparseMat const &']: f._transformer_creators.append(_FT.input_asSparseMat(arg.name)) elif pds in ["IplImage *", "IplImage const *", "CvArr *", "CvArr const *", "CvMat *", "CvMat const *", "cv::Range const *"]: f._transformer_creators.append(_FT.input_as_Mat(arg.name)) # function argument int *sizes and int dims for f in func_list: for arg in f.arguments: if is_arg_touched(f, arg.name): continue if arg.name == 'sizes' and _D.is_pointer(arg.type): for arg2 in f.arguments: if arg2.name == 'dims' and _D.is_integral(arg2.type): f._transformer_creators.append(_FT.input_array1d('sizes', 'dims')) break if arg.name == '_sizes' and _D.is_pointer(arg.type): for arg2 in f.arguments: if arg2.name == '_ndims' and _D.is_integral(arg2.type): f._transformer_creators.append(_FT.input_array1d('_sizes', '_ndims')) break if arg2.name == 'dims' and _D.is_integral(arg2.type): f._transformer_creators.append(_FT.input_array1d('_sizes', 'dims')) break if arg.name == '_newsz' and _D.is_pointer(arg.type): for arg2 in f.arguments: if arg2.name == '_newndims' and _D.is_integral(arg2.type): f._transformer_creators.append(_FT.input_array1d('_newsz', '_newndims')) break # function argument const CvPoint2D32f * src and const CvPoint2D32f * dst for f in func_list: for arg in f.arguments: if is_arg_touched(f, arg.name): continue if arg.name == 'src' and _D.is_pointer(arg.type) and 'CvPoint2D32f' in arg.type.decl_string: for arg2 in f.arguments: if arg2.name == 'dst' and _D.is_pointer(arg2.type) and 'CvPoint2D32f' in arg2.type.decl_string: f._transformer_creators.append(_FT.input_array1d('src')) f._transformer_creators.append(_FT.input_array1d('dst')) break # argument 'void *data' for f in func_list: for arg in f.arguments: if is_arg_touched(f, arg.name): continue if arg.name == 'data' and _D.is_void_pointer(arg.type): f._transformer_creators.append(_FT.input_string(arg.name)) self.add_doc(f.name, "'data' is represented by a string") # final step: apply all the function transformations for f in func_list: if len(f._transformer_creators) > 0: sort_transformers(f) f.add_transformation(*f._transformer_creators, **f._transformer_kwds) if 'unique_function_name' in f._transformer_kwds: f.transformations[0].unique_name = f._transformer_kwds['unique_function_name'] else: s = f.transformations[0].unique_name repl_dict = { 'operator()': '__call__', } for t in repl_dict: if t in s: s = s.replace(t, repl_dict[t]) f.transformations[0].unique_name = s f.transformations[0].alias = repl_dict[t] break _c.add_decl_desc(f)
const int *sz = inst.size(); if(!sz) return bp::object(); std::vector<int> result(inst.dims()); for(i = 0; i < inst.dims(); ++i) result[i] = sz[i]; return bp::object(result); } ''') z.add_registration_code( 'def("size", &::SparseMat_size, (bp::arg("i")=bp::object(-1)))') z1 = z.mem_fun( lambda x: x.name == "begin" and "const" not in x.partial_decl_string) z1.include() z1.rename("__iter__") z.mem_fun(lambda x: x.name == 'hash' and 'int const *' in x.arguments[0].type.decl_string) \ ._transformer_creators.append(FT.input_array1d('idx')) for z2 in z.mem_funs('erase'): z2._transformer_creators.append(FT.output_type1('hashval')) if z2.arguments[0].name == 'idx': z2._transformer_creators.append(FT.input_array1d('idx')) # Hdr z1 = z.class_('Hdr') sb.init_class(z1) z1.constructor(lambda x: len(x.arguments) > 1).exclude() z1.add_declaration_code(''' static boost::shared_ptr<cv::SparseMat::Hdr> SparseMat_Hdr__init1__(std::vector<int> const &_sizes, int _type) { return boost::shared_ptr<cv::SparseMat::Hdr>(new cv::SparseMat::Hdr(_sizes.size(), &_sizes[0], _type)); } ''')
z.include() if z.arguments[1].name == 'keypoints': z._transformer_creators.append(FT.arg_output('keypoints')) else: z._transformer_creators.append(FT.output(z.arguments[1].name)) FT.doc_output(z, z.arguments[1]) t = D.remove_const(D.remove_reference(z.arguments[1].type)) name = 'read_' + C_to_Python_name_dict[t.partial_decl_string] z._transformer_kwds['alias'] = name # getPerspectiveTransform, getAffineTransform for t in ('getPerspectiveTransform', 'getAffineTransform'): FT.expose_func(sb.mb.free_fun(t), return_pointee=False, transformer_creators=[ FT.input_array1d('src'), FT.input_array1d('dst') ]) # goodFeaturesToTrack FT.expose_func(sb.mb.free_fun('goodFeaturesToTrack'), return_pointee=False, transformer_creators=[FT.arg_output('corners')]) # 'HoughCircles', 'HoughLines', 'HoughLinesP' FT.expose_func(sb.mb.free_fun('HoughCircles'), return_pointee=False, transformer_creators=[FT.arg_output('circles')]) FT.expose_func(sb.mb.free_fun('HoughLines'), return_pointee=False, transformer_creators=[FT.arg_output('lines')])
if(i >= 0) return bp::object(inst.size(i)); const int *sz = inst.size(); if(!sz) return bp::object(); std::vector<int> result(inst.dims()); for(i = 0; i < inst.dims(); ++i) result[i] = sz[i]; return bp::object(result); } ''') z.add_registration_code('def("size", &::SparseMat_size, (bp::arg("i")=bp::object(-1)))') z1 = z.mem_fun(lambda x: x.name=="begin" and "const" not in x.partial_decl_string) z1.include() z1.rename("__iter__") z.mem_fun(lambda x: x.name == 'hash' and 'int const *' in x.arguments[0].type.decl_string) \ ._transformer_creators.append(FT.input_array1d('idx')) for z2 in z.mem_funs('erase'): z2._transformer_creators.append(FT.output_type1('hashval')) if z2.arguments[0].name == 'idx': z2._transformer_creators.append(FT.input_array1d('idx')) # Hdr z1 = z.class_('Hdr') sb.init_class(z1) z1.constructor(lambda x: len(x.arguments) > 1).exclude() z1.add_declaration_code(''' static boost::shared_ptr<cv::SparseMat::Hdr> SparseMat_Hdr__init1__(std::vector<int> const &_sizes, int _type) { return boost::shared_ptr<cv::SparseMat::Hdr>(new cv::SparseMat::Hdr(_sizes.size(), &_sizes[0], _type)); } ''')
for z in sb.mb.free_funs(lambda x: x.name=='read' and \ x.arguments[0].type.partial_decl_string.startswith('::cv::FileNode')): z.include() if z.arguments[1].name=='keypoints': z._transformer_creators.append(FT.arg_output('keypoints')) else: z._transformer_creators.append(FT.output(z.arguments[1].name)) FT.doc_output(z, z.arguments[1]) t = D.remove_const(D.remove_reference(z.arguments[1].type)) name = 'read_'+C_to_Python_name_dict[t.partial_decl_string] z._transformer_kwds['alias'] = name # getPerspectiveTransform, getAffineTransform for t in ('getPerspectiveTransform', 'getAffineTransform'): FT.expose_func(sb.mb.free_fun(t), return_pointee=False, transformer_creators=[FT.input_array1d('src'), FT.input_array1d('dst')]) # goodFeaturesToTrack FT.expose_func(sb.mb.free_fun('goodFeaturesToTrack'), return_pointee=False, transformer_creators=[FT.arg_output('corners')]) # 'HoughCircles', 'HoughLines', 'HoughLinesP' FT.expose_func(sb.mb.free_fun('HoughCircles'), return_pointee=False, transformer_creators=[FT.arg_output('circles')]) FT.expose_func(sb.mb.free_fun('HoughLines'), return_pointee=False, transformer_creators=[FT.arg_output('lines')]) FT.expose_func(sb.mb.free_fun('HoughLinesP'), return_pointee=False, transformer_creators=[FT.arg_output('lines')]) # getOptimalNewCameraMatrix FT.expose_func(sb.mb.free_fun('getOptimalNewCameraMatrix'), return_pointee=False,
def beautify_func_list(func_list): func_list = [f for f in func_list if not f.ignore] # fix default values # don't remove std::vector default values, old compilers _need_ std::allocator removed for f in func_list: for arg in f.arguments: if isinstance(arg.default_value, str): repl_list = { 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >': 'std::string', 'std::vector<cv::Point_<int>, std::allocator<cv::Point_<int> > >': 'std::vector<cv::Point>', 'std::vector<cv::Scalar_<double>, std::allocator<cv::Scalar_<double> > >': 'std::vector<cv::Scalar>', 'std::vector<int, std::allocator<int> >': 'std::vector<int>', 'std::vector<cv::Vec<int, 4>, std::allocator<cv::Vec<int, 4> > >': 'std::vector<cv::Vec4i>', } for z in repl_list: arg.default_value = arg.default_value.replace( z, repl_list[z]) # one-to-one function argument for f in func_list: for arg in f.arguments: if is_arg_touched(f, arg.name): continue pds = _c.unique_pds(arg.type.partial_decl_string) if pds in _c.c2cpp: f._transformer_creators.append( _FT.input_as_FixType(pds, _c.c2cpp[pds], arg.name)) elif pds in [ 'CvRNG *', 'CvRNG &', 'CvRNG cosnt *', 'CvRNG const &' ]: f._transformer_creators.append(_FT.input_asRNG(arg.name)) elif pds in ['CvFileStorage *', 'CvFileStorage const *']: f._transformer_creators.append( _FT.input_as_FileStorage(arg.name)) elif pds in ['CvFileNode *', 'CvFileNode const *']: f._transformer_creators.append(_FT.input_as_FileNode(arg.name)) elif pds in ['CvMemStorage *', 'CvMemStorage const *']: f._transformer_creators.append( _FT.input_as_MemStorage(arg.name)) elif pds in [ 'CvSparseMat *', 'CvSparseMat &', 'CvSparseMat const *', 'CvSparseMat const &' ]: f._transformer_creators.append(_FT.input_asSparseMat(arg.name)) elif pds in [ "IplImage *", "IplImage const *", "CvArr *", "CvArr const *", "CvMat *", "CvMat const *", "cv::Range const *" ]: f._transformer_creators.append(_FT.input_as_Mat(arg.name)) # function argument int *sizes and int dims for f in func_list: for arg in f.arguments: if is_arg_touched(f, arg.name): continue if arg.name == 'sizes' and _D.is_pointer(arg.type): for arg2 in f.arguments: if arg2.name == 'dims' and _D.is_integral(arg2.type): f._transformer_creators.append( _FT.input_array1d('sizes', 'dims')) break if arg.name == '_sizes' and _D.is_pointer(arg.type): for arg2 in f.arguments: if arg2.name == '_ndims' and _D.is_integral(arg2.type): f._transformer_creators.append( _FT.input_array1d('_sizes', '_ndims')) break if arg2.name == 'dims' and _D.is_integral(arg2.type): f._transformer_creators.append( _FT.input_array1d('_sizes', 'dims')) break if arg.name == '_newsz' and _D.is_pointer(arg.type): for arg2 in f.arguments: if arg2.name == '_newndims' and _D.is_integral(arg2.type): f._transformer_creators.append( _FT.input_array1d('_newsz', '_newndims')) break # function argument const CvPoint2D32f * src and const CvPoint2D32f * dst for f in func_list: for arg in f.arguments: if is_arg_touched(f, arg.name): continue if arg.name == 'src' and _D.is_pointer( arg.type) and 'CvPoint2D32f' in arg.type.decl_string: for arg2 in f.arguments: if arg2.name == 'dst' and _D.is_pointer( arg2.type ) and 'CvPoint2D32f' in arg2.type.decl_string: f._transformer_creators.append( _FT.input_array1d('src')) f._transformer_creators.append( _FT.input_array1d('dst')) break # argument 'void *data' for f in func_list: for arg in f.arguments: if is_arg_touched(f, arg.name): continue if arg.name == 'data' and _D.is_void_pointer(arg.type): f._transformer_creators.append(_FT.input_string(arg.name)) self.add_doc(f.name, "'data' is represented by a string") # final step: apply all the function transformations for f in func_list: if len(f._transformer_creators) > 0: sort_transformers(f) f.add_transformation(*f._transformer_creators, **f._transformer_kwds) if 'unique_function_name' in f._transformer_kwds: f.transformations[0].unique_name = f._transformer_kwds[ 'unique_function_name'] else: s = f.transformations[0].unique_name repl_dict = { 'operator()': '__call__', } for t in repl_dict: if t in s: s = s.replace(t, repl_dict[t]) f.transformations[0].unique_name = s f.transformations[0].alias = repl_dict[t] break _c.add_decl_desc(f)
def transform_XXXTrainData(z): z.include_files.append("arrayobject.h") # to get NumPy's flags z.include_files.append("ndarray.hpp") z.mem_fun('get_vectors')._transformer_creators.extend([ FT.input_array1d('values'), FT.input_array1d('missing'), FT.input_array1d('responses') ]) for t in ( 'get_cv_labels', 'get_sample_indices', 'get_cat_var_data', 'get_ord_var_data', ): z.mem_funs(t).exclude() z.add_declaration_code(''' static bp::object CLASS_NAME_get_cat_var_data(bp::object const &bpinst, CvDTreeNode* n, int vi) { CLASS_TYPE &inst = bp::extract<CLASS_TYPE &>(bpinst); int size = n->sample_count; sdcpp::ndarray result = sdcpp::simplenew_ndarray(1, &size, NPY_INT); int *in_arr = (int*)result.data(); const int *out_arr = inst.get_cat_var_data(n, vi, in_arr); if(!out_arr) return bp::object(); if(out_arr == in_arr) return result.get_obj(); result = sdcpp::new_ndarray1d(size, NPY_INT, (void *)out_arr); bp::objects::make_nurse_and_patient(result.get_obj().ptr(), bpinst.ptr()); return result.get_obj(); } static bp::object CLASS_NAME_get_cv_labels(bp::object const &bpinst, CvDTreeNode* n) { CLASS_TYPE &inst = bp::extract<CLASS_TYPE &>(bpinst); int size = n->sample_count; sdcpp::ndarray result = sdcpp::simplenew_ndarray(1, &size, NPY_INT); int *in_arr = (int*)result.data(); const int *out_arr = inst.get_cv_labels(n, in_arr); if(!out_arr) return bp::object(); if(out_arr == in_arr) return result.get_obj(); result = sdcpp::new_ndarray1d(size, NPY_INT, (void *)out_arr); bp::objects::make_nurse_and_patient(result.get_obj().ptr(), bpinst.ptr()); return result.get_obj(); } static bp::object CLASS_NAME_get_sample_indices(bp::object const &bpinst, CvDTreeNode* n) { CLASS_TYPE &inst = bp::extract<CLASS_TYPE &>(bpinst); int size = n->sample_count; sdcpp::ndarray result = sdcpp::simplenew_ndarray(1, &size, NPY_INT); int *in_arr = (int*)result.data(); const int *out_arr = inst.get_sample_indices(n, in_arr); if(!out_arr) return bp::object(); if(out_arr == in_arr) return result.get_obj(); result = sdcpp::new_ndarray1d(size, NPY_INT, (void *)out_arr); bp::objects::make_nurse_and_patient(result.get_obj().ptr(), bpinst.ptr()); return result.get_obj(); } static bp::tuple CLASS_NAME_get_ord_var_data(bp::object const &bpinst, CvDTreeNode* n, int vi) { CLASS_TYPE &inst = bp::extract<CLASS_TYPE &>(bpinst); int size = n->sample_count; std::vector<int> sample_indices(size); sdcpp::ndarray result1 = sdcpp::simplenew_ndarray(1, &size, NPY_FLOAT); sdcpp::ndarray result2 = sdcpp::simplenew_ndarray(1, &size, NPY_INT); float *in_arr1 = (float*)result1.data(); int *in_arr2 = (int*)result2.data(); const float *out_arr1; const int *out_arr2; inst.get_ord_var_data(n, vi, in_arr1, in_arr2, &out_arr1, &out_arr2, &sample_indices[0]); bp::object obj1, obj2; if(out_arr1 && out_arr1 != in_arr1) { result1 = sdcpp::new_ndarray1d(size, NPY_FLOAT, (void *)out_arr1); bp::objects::make_nurse_and_patient(result1.get_obj().ptr(), bpinst.ptr()); } if(out_arr1) obj1 = result1.get_obj(); if(out_arr2 && out_arr2 != in_arr2) { result2 = sdcpp::new_ndarray1d(size, NPY_INT, (void *)out_arr2); bp::objects::make_nurse_and_patient(result2.get_obj().ptr(), bpinst.ptr()); } if(out_arr2) obj2 = result2.get_obj(); return bp::make_tuple(obj1, obj2); } '''.replace("CLASS_NAME", z.alias).replace("CLASS_TYPE", z.pds)) z.add_registration_code( 'def("get_cat_var_data", &::CLASS_NAME_get_cat_var_data, (bp::arg("self"), bp::arg("n"), bp::arg("vi")))' .replace("CLASS_NAME", z.alias)) z.add_registration_code( 'def("get_cv_labels", &::CLASS_NAME_get_cv_labels, (bp::arg("self"), bp::arg("n")))' .replace("CLASS_NAME", z.alias)) z.add_registration_code( 'def("get_sample_indices", &::CLASS_NAME_get_sample_indices, (bp::arg("self"), bp::arg("n")))' .replace("CLASS_NAME", z.alias)) z.add_registration_code( 'def("get_ord_var_data", &::CLASS_NAME_get_ord_var_data, (bp::arg("self"), bp::arg("n"), bp::arg("vi")))' .replace("CLASS_NAME", z.alias))
# CvDTreeNode z = sb.mb.class_('CvDTreeNode') sb.init_class(z) for t in ('parent', 'left', 'right', 'split'): FT.expose_member_as_pointee(z, t) for t in ('num_valid', 'cv_Tn', 'cv_node_risk', 'cv_node_error'): z.var(t).exclude() # members for internal use, no need to expose sb.finalize_class(z) # CvDTreeParams z = sb.mb.class_('CvDTreeParams') sb.init_class(z) FT.expose_member_as_ndarray1d(z, 'priors', 'inst.max_categories') z.constructor(lambda x: len(x.arguments) > 1)._transformer_creators.append( FT.input_array1d('_priors')) sb.finalize_class(z) # ...TrainData functions def transform_XXXTrainData(z): z.include_files.append("arrayobject.h") # to get NumPy's flags z.include_files.append("ndarray.hpp") z.mem_fun('get_vectors')._transformer_creators.extend([ FT.input_array1d('values'), FT.input_array1d('missing'), FT.input_array1d('responses') ]) for t in ( 'get_cv_labels', 'get_sample_indices',
'cvCalcMotionGradient', 'cvCalcGlobalOrientation', 'cvAcc', 'cvSquareAcc', 'cvMultiplyAcc', 'cvRunningAvg', ): sb.mb.free_fun(z).include() # cvCalcOpticalFlowPyrLK FT.expose_func(sb.mb.free_fun('cvCalcOpticalFlowPyrLK'), return_pointee=False, transformer_creators=[ FT.input_array1d('prev_features', 'count', output_arrays=[('curr_features', '1'), ('status', '1'), ('track_error', '1')]) ]) # cvCalcAffineFlowPyrLK FT.expose_func(sb.mb.free_fun('cvCalcAffineFlowPyrLK'), return_pointee=False, transformer_creators=[ FT.input_array1d('prev_features', 'count', output_arrays=[('curr_features', '1'), ('matrices', '1'), ('status', '1'), ('track_error', '1')]) ])