diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt index af062cebc741e45e4a2a41c1b5be8943743a6ee5..66ac1addd614c37271e72fc54574f8df5173c470 100644 --- a/modules/python/CMakeLists.txt +++ b/modules/python/CMakeLists.txt @@ -11,7 +11,25 @@ if(ANDROID OR IOS OR NOT PYTHONLIBS_FOUND OR NOT PYTHON_NUMPY_INCLUDE_DIRS) endif() set(the_description "The python bindings") -ocv_add_module(python BINDINGS opencv_core opencv_flann opencv_imgproc opencv_video opencv_ml opencv_features2d opencv_imgcodecs opencv_videoio opencv_highgui opencv_calib3d opencv_photo opencv_objdetect OPTIONAL opencv_nonfree) + +set(candidate_deps "") +foreach(mp ${OPENCV_MODULES_PATH} ${OPENCV_EXTRA_MODULES_PATH}) + file(GLOB names "${mp}/*") + foreach(m IN LISTS names) + if(IS_DIRECTORY ${m}) + get_filename_component(m ${m} NAME) + list(APPEND candidate_deps "opencv_${m}") + endif() + endforeach(m) +endforeach(mp) + +# module blacklist +ocv_list_filterout(candidate_deps "^opencv_cud(a|ev)") +ocv_list_filterout(candidate_deps "^opencv_adas$") +ocv_list_filterout(candidate_deps "^opencv_tracking$") + + +ocv_add_module(python BINDINGS OPTIONAL ${candidate_deps}) ocv_module_include_directories( "${PYTHON_INCLUDE_PATH}" @@ -19,31 +37,17 @@ ocv_module_include_directories( "${CMAKE_CURRENT_SOURCE_DIR}/src2" ) -set(opencv_hdrs - "${OPENCV_MODULE_opencv_core_LOCATION}/include/opencv2/core.hpp" - "${OPENCV_MODULE_opencv_core_LOCATION}/include/opencv2/core/base.hpp" - "${OPENCV_MODULE_opencv_core_LOCATION}/include/opencv2/core/types.hpp" - "${OPENCV_MODULE_opencv_core_LOCATION}/include/opencv2/core/persistence.hpp" - "${OPENCV_MODULE_opencv_core_LOCATION}/include/opencv2/core/utility.hpp" - "${OPENCV_MODULE_opencv_core_LOCATION}/include/opencv2/core/ocl.hpp" - "${OPENCV_MODULE_opencv_flann_LOCATION}/include/opencv2/flann/miniflann.hpp" - "${OPENCV_MODULE_opencv_imgproc_LOCATION}/include/opencv2/imgproc.hpp" - "${OPENCV_MODULE_opencv_video_LOCATION}/include/opencv2/video/background_segm.hpp" - "${OPENCV_MODULE_opencv_video_LOCATION}/include/opencv2/video/tracking.hpp" - "${OPENCV_MODULE_opencv_photo_LOCATION}/include/opencv2/photo.hpp" - "${OPENCV_MODULE_opencv_imgcodecs_LOCATION}/include/opencv2/imgcodecs.hpp" - "${OPENCV_MODULE_opencv_videoio_LOCATION}/include/opencv2/videoio.hpp" - "${OPENCV_MODULE_opencv_highgui_LOCATION}/include/opencv2/highgui.hpp" - "${OPENCV_MODULE_opencv_ml_LOCATION}/include/opencv2/ml.hpp" - "${OPENCV_MODULE_opencv_features2d_LOCATION}/include/opencv2/features2d.hpp" - "${OPENCV_MODULE_opencv_calib3d_LOCATION}/include/opencv2/calib3d.hpp" - "${OPENCV_MODULE_opencv_objdetect_LOCATION}/include/opencv2/objdetect.hpp" - ) -if(HAVE_opencv_nonfree) - list(APPEND opencv_hdrs "${OPENCV_MODULE_opencv_nonfree_LOCATION}/include/opencv2/nonfree/features2d.hpp" - "${OPENCV_MODULE_opencv_nonfree_LOCATION}/include/opencv2/nonfree.hpp") -endif() +set(opencv_hdrs "") +foreach(m IN LISTS OPENCV_MODULE_opencv_python_DEPS) + list(APPEND opencv_hdrs ${OPENCV_MODULE_${m}_HEADERS}) +endforeach(m) + +# header blacklist +ocv_list_filterout(opencv_hdrs ".h$") +ocv_list_filterout(opencv_hdrs "opencv2/core/cuda") +ocv_list_filterout(opencv_hdrs "opencv2/objdetect/detection_based_tracker.hpp") +ocv_list_filterout(opencv_hdrs "opencv2/optim.hpp") set(cv2_generated_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_include.h" @@ -53,11 +57,13 @@ set(cv2_generated_hdrs "${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_type_reg.h" "${CMAKE_CURRENT_BINARY_DIR}/pyopencv_generated_const_reg.h") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/headers.txt" "${opencv_hdrs}") add_custom_command( OUTPUT ${cv2_generated_hdrs} - COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py" ${CMAKE_CURRENT_BINARY_DIR} ${opencv_hdrs} + COMMAND ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py" ${CMAKE_CURRENT_BINARY_DIR} "${CMAKE_CURRENT_BINARY_DIR}/headers.txt" DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/gen2.py DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src2/hdr_parser.py + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/headers.txt DEPENDS ${opencv_hdrs}) add_library(${the_module} SHARED src2/cv2.cpp ${cv2_generated_hdrs}) diff --git a/modules/python/src2/gen2.py b/modules/python/src2/gen2.py index b613ccd4acfa008923e57939eb0948015b0b9be4..684b80f4e8c4994ce72c83fbd263f0f4de4fb62c 100755 --- a/modules/python/src2/gen2.py +++ b/modules/python/src2/gen2.py @@ -831,8 +831,10 @@ 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.rindex('opencv2/'):]) ) decls = parser.parse(hdr) + if len(decls) == 0: + continue + self.code_include.write( '#include "{}"\n'.format(hdr[hdr.rindex('opencv2/'):]) ) for decl in decls: name = decl[0] if name.startswith("struct") or name.startswith("class"): @@ -901,6 +903,6 @@ if __name__ == "__main__": if len(sys.argv) > 1: dstdir = sys.argv[1] if len(sys.argv) > 2: - srcfiles = sys.argv[2:] + srcfiles = open(sys.argv[2], 'r').read().split(';') generator = PythonWrapperGenerator() generator.gen(srcfiles, dstdir) diff --git a/modules/python/src2/hdr_parser.py b/modules/python/src2/hdr_parser.py index 92f1b7347c7322014d7d64308050d50462af4dbd..eb9100928f9e3f4cc64492daec062cfe16a8f890 100755 --- a/modules/python/src2/hdr_parser.py +++ b/modules/python/src2/hdr_parser.py @@ -206,6 +206,8 @@ class CppHeaderParser(object): def parse_enum(self, decl_str): l = decl_str ll = l.split(",") + if ll[-1].strip() == "": + ll = ll[:-1] prev_val = "" prev_val_delta = -1 decl = [] diff --git a/modules/shape/include/opencv2/shape/hist_cost.hpp b/modules/shape/include/opencv2/shape/hist_cost.hpp index 9ca3825fdaf066e1e4733581ea885a5248f40c5a..0ff3573eea0ff43687863fbae466897f6f62ba96 100644 --- a/modules/shape/include/opencv2/shape/hist_cost.hpp +++ b/modules/shape/include/opencv2/shape/hist_cost.hpp @@ -73,7 +73,7 @@ public: }; CV_EXPORTS_W Ptr - createNormHistogramCostExtractor(int flag=DIST_L2, int nDummies=25, float defaultCost=0.2); + createNormHistogramCostExtractor(int flag=DIST_L2, int nDummies=25, float defaultCost=0.2f); /*! */ class CV_EXPORTS_W EMDHistogramCostExtractor : public HistogramCostExtractor @@ -84,20 +84,20 @@ public: }; CV_EXPORTS_W Ptr - createEMDHistogramCostExtractor(int flag=DIST_L2, int nDummies=25, float defaultCost=0.2); + createEMDHistogramCostExtractor(int flag=DIST_L2, int nDummies=25, float defaultCost=0.2f); /*! */ class CV_EXPORTS_W ChiHistogramCostExtractor : public HistogramCostExtractor {}; -CV_EXPORTS_W Ptr createChiHistogramCostExtractor(int nDummies=25, float defaultCost=0.2); +CV_EXPORTS_W Ptr createChiHistogramCostExtractor(int nDummies=25, float defaultCost=0.2f); /*! */ class CV_EXPORTS_W EMDL1HistogramCostExtractor : public HistogramCostExtractor {}; CV_EXPORTS_W Ptr - createEMDL1HistogramCostExtractor(int nDummies=25, float defaultCost=0.2); + createEMDL1HistogramCostExtractor(int nDummies=25, float defaultCost=0.2f); } // cv #endif diff --git a/modules/shape/include/opencv2/shape/shape_distance.hpp b/modules/shape/include/opencv2/shape/shape_distance.hpp index 55e21aaa4a8c7d7fafc7fc1ee99b44f0fca7c0ab..acdb6e5f6e644f3beaf4de3d53dc9ac83110cd56 100644 --- a/modules/shape/include/opencv2/shape/shape_distance.hpp +++ b/modules/shape/include/opencv2/shape/shape_distance.hpp @@ -116,7 +116,7 @@ public: /* Complete constructor */ CV_EXPORTS_W Ptr createShapeContextDistanceExtractor(int nAngularBins=12, int nRadialBins=4, - float innerRadius=0.2, float outerRadius=2, int iterations=3, + float innerRadius=0.2f, float outerRadius=2, int iterations=3, const Ptr &comparer = createChiHistogramCostExtractor(), const Ptr &transformer = createThinPlateSplineShapeTransformer()); @@ -137,7 +137,7 @@ public: }; /* Constructor */ -CV_EXPORTS_W Ptr createHausdorffDistanceExtractor(int distanceFlag=cv::NORM_L2, float rankProp=0.6); +CV_EXPORTS_W Ptr createHausdorffDistanceExtractor(int distanceFlag=cv::NORM_L2, float rankProp=0.6f); } // cv #endif