Work on python wrapped generation automation:
- all parsed headers are included into "cv2.cpp" with "pyopencv_generated_include.h" - types starting with "Ptr_" converted to "Ptr<...>" form (avoids many typedefs in "cv2.cpp")
This commit is contained in:
parent
e1b5a547cc
commit
120b3a1e77
@ -44,6 +44,7 @@ if(HAVE_opencv_nonfree)
|
||||
endif()
|
||||
|
||||
set(cv2_generated_hdrs
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_include.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_funcs.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_func_tab.h"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_types.h"
|
||||
|
@ -9,30 +9,12 @@
|
||||
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
|
||||
#include <numpy/ndarrayobject.h>
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/utility.hpp"
|
||||
#include "opencv2/contrib.hpp"
|
||||
#include "opencv2/flann/miniflann.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/calib3d.hpp"
|
||||
#include "opencv2/features2d.hpp"
|
||||
#include "opencv2/objdetect.hpp"
|
||||
#include "opencv2/softcascade.hpp"
|
||||
#include "opencv2/video.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
#include "opencv2/ml.hpp"
|
||||
#include "pyopencv_generated_include.h"
|
||||
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#ifdef HAVE_OPENCV_NONFREE
|
||||
# include "opencv2/nonfree.hpp"
|
||||
#endif
|
||||
|
||||
#include "pycompat.hpp"
|
||||
|
||||
using cv::flann::IndexParams;
|
||||
using cv::flann::SearchParams;
|
||||
|
||||
static PyObject* opencv_error = 0;
|
||||
|
||||
@ -100,7 +82,9 @@ catch (const cv::Exception &e) \
|
||||
}
|
||||
|
||||
using namespace cv;
|
||||
typedef cv::softcascade::ChannelFeatureBuilder softcascade_ChannelFeatureBuilder;
|
||||
using cv::flann::IndexParams;
|
||||
using cv::flann::SearchParams;
|
||||
using cv::softcascade::ChannelFeatureBuilder;
|
||||
|
||||
typedef std::vector<uchar> vector_uchar;
|
||||
typedef std::vector<char> vector_char;
|
||||
@ -119,6 +103,7 @@ typedef std::vector<KeyPoint> vector_KeyPoint;
|
||||
typedef std::vector<Mat> vector_Mat;
|
||||
typedef std::vector<DMatch> vector_DMatch;
|
||||
typedef std::vector<String> vector_String;
|
||||
typedef std::vector<Scalar> vector_Scalar;
|
||||
|
||||
typedef std::vector<std::vector<char> > vector_vector_char;
|
||||
typedef std::vector<std::vector<Point> > vector_vector_Point;
|
||||
@ -126,47 +111,13 @@ typedef std::vector<std::vector<Point2f> > vector_vector_Point2f;
|
||||
typedef std::vector<std::vector<Point3f> > vector_vector_Point3f;
|
||||
typedef std::vector<std::vector<DMatch> > vector_vector_DMatch;
|
||||
|
||||
typedef Ptr<Algorithm> Ptr_Algorithm;
|
||||
typedef Ptr<FeatureDetector> Ptr_FeatureDetector;
|
||||
typedef Ptr<DescriptorExtractor> Ptr_DescriptorExtractor;
|
||||
typedef Ptr<Feature2D> Ptr_Feature2D;
|
||||
typedef Ptr<DescriptorMatcher> Ptr_DescriptorMatcher;
|
||||
typedef Ptr<BackgroundSubtractor> Ptr_BackgroundSubtractor;
|
||||
typedef Ptr<BackgroundSubtractorMOG> Ptr_BackgroundSubtractorMOG;
|
||||
typedef Ptr<BackgroundSubtractorMOG2> Ptr_BackgroundSubtractorMOG2;
|
||||
typedef Ptr<BackgroundSubtractorKNN> Ptr_BackgroundSubtractorKNN;
|
||||
typedef Ptr<BackgroundSubtractorGMG> Ptr_BackgroundSubtractorGMG;
|
||||
|
||||
typedef Ptr<StereoMatcher> Ptr_StereoMatcher;
|
||||
typedef Ptr<StereoBM> Ptr_StereoBM;
|
||||
typedef Ptr<StereoSGBM> Ptr_StereoSGBM;
|
||||
|
||||
typedef Ptr<Tonemap> Ptr_Tonemap;
|
||||
typedef Ptr<TonemapDrago> Ptr_TonemapDrago;
|
||||
typedef Ptr<TonemapReinhard> Ptr_TonemapReinhard;
|
||||
typedef Ptr<TonemapDurand> Ptr_TonemapDurand;
|
||||
typedef Ptr<TonemapMantiuk> Ptr_TonemapMantiuk;
|
||||
typedef Ptr<AlignMTB> Ptr_AlignMTB;
|
||||
typedef Ptr<CalibrateDebevec> Ptr_CalibrateDebevec;
|
||||
typedef Ptr<CalibrateRobertson> Ptr_CalibrateRobertson;
|
||||
typedef Ptr<MergeDebevec> Ptr_MergeDebevec;
|
||||
typedef Ptr<MergeRobertson> Ptr_MergeRobertson;
|
||||
typedef Ptr<MergeMertens> Ptr_MergeMertens;
|
||||
typedef Ptr<MergeRobertson> Ptr_MergeRobertson;
|
||||
|
||||
typedef Ptr<cv::softcascade::ChannelFeatureBuilder> Ptr_ChannelFeatureBuilder;
|
||||
typedef Ptr<CLAHE> Ptr_CLAHE;
|
||||
typedef Ptr<LineSegmentDetector > Ptr_LineSegmentDetector;
|
||||
typedef cv::softcascade::ChannelFeatureBuilder softcascade_ChannelFeatureBuilder;
|
||||
|
||||
typedef SimpleBlobDetector::Params SimpleBlobDetector_Params;
|
||||
|
||||
typedef cvflann::flann_distance_t cvflann_flann_distance_t;
|
||||
typedef cvflann::flann_algorithm_t cvflann_flann_algorithm_t;
|
||||
typedef Ptr<flann::IndexParams> Ptr_flann_IndexParams;
|
||||
typedef Ptr<flann::SearchParams> Ptr_flann_SearchParams;
|
||||
|
||||
typedef Ptr<FaceRecognizer> Ptr_FaceRecognizer;
|
||||
typedef std::vector<Scalar> vector_Scalar;
|
||||
|
||||
static PyObject* failmsgp(const char *fmt, ...)
|
||||
{
|
||||
|
@ -351,9 +351,15 @@ class ConstInfo(object):
|
||||
self.name = self.name.upper()
|
||||
self.value = val
|
||||
|
||||
def handle_ptr(tp):
|
||||
if tp.startswith('Ptr_'):
|
||||
tp = 'Ptr<' + "::".join(tp.split('_')[1:]) + '>'
|
||||
return tp
|
||||
|
||||
|
||||
class ArgInfo(object):
|
||||
def __init__(self, arg_tuple):
|
||||
self.tp = arg_tuple[0]
|
||||
self.tp = handle_ptr(arg_tuple[0])
|
||||
self.name = arg_tuple[1]
|
||||
self.defval = arg_tuple[2]
|
||||
self.isarray = False
|
||||
@ -398,7 +404,7 @@ class FuncVariant(object):
|
||||
else:
|
||||
self.wname = self.classname
|
||||
|
||||
self.rettype = decl[1]
|
||||
self.rettype = handle_ptr(decl[1])
|
||||
if self.rettype == "void":
|
||||
self.rettype = ""
|
||||
self.args = []
|
||||
@ -736,6 +742,7 @@ class PythonWrapperGenerator(object):
|
||||
self.classes = {}
|
||||
self.funcs = {}
|
||||
self.consts = {}
|
||||
self.code_include = StringIO()
|
||||
self.code_types = StringIO()
|
||||
self.code_funcs = StringIO()
|
||||
self.code_func_tab = StringIO()
|
||||
@ -823,6 +830,7 @@ class PythonWrapperGenerator(object):
|
||||
|
||||
# step 1: scan the headers and build more descriptive maps of classes, consts, functions
|
||||
for hdr in srcfiles:
|
||||
self.code_include.write( '#include "{}"\n'.format(hdr[hdr.find('opencv2/'):]) )
|
||||
decls = parser.parse(hdr)
|
||||
for decl in decls:
|
||||
name = decl[0]
|
||||
@ -879,6 +887,7 @@ class PythonWrapperGenerator(object):
|
||||
self.gen_const_reg(constinfo)
|
||||
|
||||
# That's it. Now save all the files
|
||||
self.save(output_path, "pyopencv_generated_include.h", self.code_include)
|
||||
self.save(output_path, "pyopencv_generated_funcs.h", self.code_funcs)
|
||||
self.save(output_path, "pyopencv_generated_func_tab.h", self.code_func_tab)
|
||||
self.save(output_path, "pyopencv_generated_const_reg.h", self.code_const_reg)
|
||||
|
Loading…
Reference in New Issue
Block a user