From 62414e3073eeec874305e858b297ed8dba5a1b89 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 4 Oct 2021 10:46:32 +0000 Subject: [PATCH 1/3] core(parallel): suppress TSAN warning --- modules/core/src/parallel_impl.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/core/src/parallel_impl.cpp b/modules/core/src/parallel_impl.cpp index 7f30c9d5f3..1d9690b04c 100644 --- a/modules/core/src/parallel_impl.cpp +++ b/modules/core/src/parallel_impl.cpp @@ -615,6 +615,11 @@ void ThreadPool::run(const Range& range, const ParallelLoopBody& body, double ns { WorkerThread& thread = *(threads[i].get()); if ( +#if defined(__clang__) && defined(__has_feature) +#if __has_feature(thread_sanitizer) + 1 || // Robust workaround to avoid data race warning of `thread.job` +#endif +#endif #if !defined(CV_USE_GLOBAL_WORKERS_COND_VAR) thread.isActive || #endif From 24f43e7ae91feda546f884dbba1ff858e1c1ed25 Mon Sep 17 00:00:00 2001 From: xhawk18 Date: Tue, 5 Oct 2021 00:44:57 +0800 Subject: [PATCH 2/3] Merge pull request #20183 from xhawk18:3.4 * improve compatibility for qt 6. * cmake(highgui): rework Qt dependency support * cmake(highgui): workaround Qt5Config.cmake "components" bug Co-authored-by: Alexander Alekhin --- CMakeLists.txt | 15 ++++--- cmake/OpenCVDetectVTK.cmake | 29 +++--------- cmake/OpenCVFindLibsGUI.cmake | 59 +++++++++++++++++------- modules/highgui/CMakeLists.txt | 75 +++++++++++++++++-------------- modules/highgui/src/window_QT.cpp | 52 ++++++++++++++++++--- 5 files changed, 145 insertions(+), 85 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94ef43fcb4..d9f98bf23e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1232,12 +1232,17 @@ status("") status(" GUI: ") if(WITH_QT OR HAVE_QT) - if(HAVE_QT5) - status(" QT:" "YES (ver ${Qt5Core_VERSION_STRING})") - status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO) - elseif(HAVE_QT) + if(HAVE_QT) status(" QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})") - status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO) + if(HAVE_QT_OPENGL) + if(Qt${QT_VERSION_MAJOR}OpenGL_LIBRARIES) + status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt${QT_VERSION_MAJOR}OpenGL_LIBRARIES} ${Qt${QT_VERSION_MAJOR}OpenGL_VERSION_STRING})" ELSE NO) + else() + status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO) + endif() + else() + status(" QT OpenGL support:" "NO") + endif() else() status(" QT:" "NO") endif() diff --git a/cmake/OpenCVDetectVTK.cmake b/cmake/OpenCVDetectVTK.cmake index 14956886e3..94ab735592 100644 --- a/cmake/OpenCVDetectVTK.cmake +++ b/cmake/OpenCVDetectVTK.cmake @@ -26,31 +26,14 @@ if(VTK_VERSION VERSION_LESS "5.8.0") endif() # Different Qt versions can't be linked together -if(HAVE_QT5 AND VTK_VERSION VERSION_LESS "6.0.0") - if(VTK_USE_QT) - message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt5 and VTK ver.${VTK_VERSION} + Qt4") - endif() -endif() - -# Different Qt versions can't be linked together. VTK 6.0.0 doesn't provide a way to get Qt version it was linked with -if(HAVE_QT5 AND VTK_VERSION VERSION_EQUAL "6.0.0" AND NOT DEFINED FORCE_VTK) - message(STATUS "VTK support is disabled. Possible incompatible combination: OpenCV+Qt5, and VTK ver.${VTK_VERSION} with Qt4") - message(STATUS "If it is known that VTK was compiled without Qt4, please define '-DFORCE_VTK=TRUE' flag in CMake") +if((HAVE_QT AND VTK_USE_QT) + AND NOT DEFINED FORCE_VTK # deprecated + AND NOT DEFINED OPENCV_FORCE_VTK +) + message(STATUS "VTK support is disabled. Possible incompatible combination: OpenCV+Qt, and VTK ver.${VTK_VERSION} with Qt") + message(STATUS "If it is known that VTK was compiled without Qt4, please define '-DOPENCV_FORCE_VTK=TRUE' flag in CMake") return() endif() -# Different Qt versions can't be linked together -if(HAVE_QT AND VTK_VERSION VERSION_GREATER "6.0.0" AND NOT ${VTK_QT_VERSION} STREQUAL "") - if(HAVE_QT5 AND ${VTK_QT_VERSION} EQUAL "4") - message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt5 and VTK ver.${VTK_VERSION} + Qt4") - return() - endif() - - if(NOT HAVE_QT5 AND ${VTK_QT_VERSION} EQUAL "5") - message(STATUS "VTK support is disabled. Incompatible combination: OpenCV + Qt4 and VTK ver.${VTK_VERSION} + Qt5") - return() - endif() -endif() - set(HAVE_VTK ON) message(STATUS "Found VTK ${VTK_VERSION} (${VTK_USE_FILE})") diff --git a/cmake/OpenCVFindLibsGUI.cmake b/cmake/OpenCVFindLibsGUI.cmake index 82f7e0ff12..5e7db6c199 100644 --- a/cmake/OpenCVFindLibsGUI.cmake +++ b/cmake/OpenCVFindLibsGUI.cmake @@ -11,25 +11,50 @@ if(WITH_WIN32UI) CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=user32;gdi32") endif() -# --- QT4 --- -ocv_clear_vars(HAVE_QT HAVE_QT5) -if(WITH_QT) - if(NOT WITH_QT EQUAL 4) - find_package(Qt5 COMPONENTS Core Gui Widgets Test Concurrent REQUIRED NO_MODULE) - if(Qt5_FOUND) - set(HAVE_QT5 ON) - set(HAVE_QT ON) - find_package(Qt5 COMPONENTS OpenGL QUIET) - if(Qt5OpenGL_FOUND) - set(QT_QTOPENGL_FOUND ON) - endif() - endif() +macro(ocv_find_package_Qt4) + find_package(Qt4 COMPONENTS QtCore QtGui QtTest ${ARGN}) + if(QT4_FOUND) + set(QT_FOUND 1) + ocv_assert(QT_VERSION_MAJOR EQUAL 4) endif() +endmacro() - if(NOT HAVE_QT) - find_package(Qt4 REQUIRED QtCore QtGui QtTest) - if(QT4_FOUND) - set(HAVE_QT TRUE) +macro(ocv_find_package_Qt OCV_QT_VER) + find_package(Qt${OCV_QT_VER} COMPONENTS Core Gui Widgets Test Concurrent ${ARGN} NO_MODULE) + if(Qt${OCV_QT_VER}_FOUND) + set(QT_FOUND 1) + set(QT_VERSION "${Qt${OCV_QT_VER}_VERSION}") + set(QT_VERSION_MAJOR "${Qt${OCV_QT_VER}_VERSION_MAJOR}") + set(QT_VERSION_MINOR "${Qt${OCV_QT_VER}_VERSION_MINOR}") + set(QT_VERSION_PATCH "${Qt${OCV_QT_VER}_VERSION_PATCH}") + set(QT_VERSION_TWEAK "${Qt${OCV_QT_VER}_VERSION_TWEAK}") + set(QT_VERSION_COUNT "${Qt${OCV_QT_VER}_VERSION_COUNT}") + endif() +endmacro() + +# --- QT4 --- +if(WITH_QT) + if(NOT WITH_QT GREATER 0) + # BUG: Qt5Config.cmake script can't handle components properly: find_package(QT NAMES Qt6 Qt5 REQUIRED NO_MODULE COMPONENTS Core Gui Widgets Test Concurrent) + ocv_find_package_Qt(6 QUIET) + if(NOT QT_FOUND) + ocv_find_package_Qt(5 QUIET) + endif() + if(NOT QT_FOUND) + ocv_find_package_Qt4(QUIET) + endif() + elseif(WITH_QT EQUAL 4) + ocv_find_package_Qt4(REQUIRED) + else() # WITH_QT= + ocv_find_package_Qt("${WITH_QT}" REQUIRED) + endif() + if(QT_FOUND) + set(HAVE_QT ON) + if(QT_VERSION_MAJOR GREATER 4) + find_package(Qt${QT_VERSION_MAJOR} COMPONENTS OpenGL QUIET) + if(Qt${QT_VERSION_MAJOR}OpenGL_FOUND) + set(QT_QTOPENGL_FOUND ON) # HAVE_QT_OPENGL is defined below + endif() endif() endif() endif() diff --git a/modules/highgui/CMakeLists.txt b/modules/highgui/CMakeLists.txt index 296f4cab2b..6e69961099 100644 --- a/modules/highgui/CMakeLists.txt +++ b/modules/highgui/CMakeLists.txt @@ -41,46 +41,55 @@ file(GLOB highgui_ext_hdrs # Removing WinRT API headers by default list(REMOVE_ITEM highgui_ext_hdrs "${CMAKE_CURRENT_LIST_DIR}/include/opencv2/${name}/highgui_winrt.hpp") -if(HAVE_QT5) - # "Automoc" doesn't work properly with opencv_world build, use QT5_WRAP_CPP() directly - #set(CMAKE_AUTOMOC ON) +if(HAVE_QT) + if(QT_VERSION_MAJOR GREATER 4) + # "Automoc" doesn't work properly with opencv_world build, use QT_WRAP_CPP() directly + #set(CMAKE_AUTOMOC ON) - set(CMAKE_INCLUDE_CURRENT_DIR ON) + set(CMAKE_INCLUDE_CURRENT_DIR ON) - QT5_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc) - QT5_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h) - list(APPEND highgui_srcs - ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.cpp - ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h - ${_MOC_OUTFILES} - ${_RCC_OUTFILES}) + if(QT_VERSION_MAJOR EQUAL 6) + QT6_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc) + QT6_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h) + elseif(QT_VERSION_MAJOR EQUAL 5) + QT5_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc) + QT5_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h) + else() + message(FATAL_ERROR "Unsuported QT version: ${QT_VERSION_MAJOR}") + endif() - foreach(dt5_dep Core Gui Widgets Test Concurrent) - add_definitions(${Qt5${dt5_dep}_DEFINITIONS}) - include_directories(${Qt5${dt5_dep}_INCLUDE_DIRS}) - list(APPEND HIGHGUI_LIBRARIES ${Qt5${dt5_dep}_LIBRARIES}) - endforeach() + list(APPEND highgui_srcs + ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.cpp + ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h + ${_MOC_OUTFILES} + ${_RCC_OUTFILES}) - if(HAVE_QT_OPENGL) - add_definitions(${Qt5OpenGL_DEFINITIONS}) - include_directories(${Qt5OpenGL_INCLUDE_DIRS}) - list(APPEND HIGHGUI_LIBRARIES ${Qt5OpenGL_LIBRARIES}) - endif() + set(qt_deps Core Gui Widgets Test Concurrent) + if(HAVE_QT_OPENGL) + list(APPEND qt_deps OpenGL) + endif() -elseif(HAVE_QT) - if (HAVE_QT_OPENGL) - set(QT_USE_QTOPENGL TRUE) - endif() - include(${QT_USE_FILE}) + foreach(dt_dep ${qt_deps}) + add_definitions(${Qt${QT_VERSION_MAJOR}${dt_dep}_DEFINITIONS}) + include_directories(${Qt${QT_VERSION_MAJOR}${dt_dep}_INCLUDE_DIRS}) + list(APPEND HIGHGUI_LIBRARIES ${Qt${QT_VERSION_MAJOR}${dt_dep}_LIBRARIES}) + endforeach() + else() + ocv_assert(QT_VERSION_MAJOR EQUAL 4) + if (HAVE_QT_OPENGL) + set(QT_USE_QTOPENGL TRUE) + endif() + include(${QT_USE_FILE}) - QT4_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc) - QT4_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h) + QT4_ADD_RESOURCES(_RCC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.qrc) + QT4_WRAP_CPP(_MOC_OUTFILES ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.h) - list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES}) - list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES}) - ocv_check_flag_support(CXX -Wno-missing-declarations _have_flag "") - if(${_have_flag}) - set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations) + list(APPEND HIGHGUI_LIBRARIES ${QT_LIBRARIES}) + list(APPEND highgui_srcs ${CMAKE_CURRENT_LIST_DIR}/src/window_QT.cpp ${_MOC_OUTFILES} ${_RCC_OUTFILES}) + ocv_check_flag_support(CXX -Wno-missing-declarations _have_flag "") + if(${_have_flag}) + set_source_files_properties(${_RCC_OUTFILES} PROPERTIES COMPILE_FLAGS -Wno-missing-declarations) + endif() endif() elseif(WINRT) if(NOT WINRT_8_0) diff --git a/modules/highgui/src/window_QT.cpp b/modules/highgui/src/window_QT.cpp index 8dff03117e..e7ee43cf5e 100644 --- a/modules/highgui/src/window_QT.cpp +++ b/modules/highgui/src/window_QT.cpp @@ -64,6 +64,38 @@ #endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) +#define Qt_MiddleButton Qt::MiddleButton +inline Qt::Orientation wheelEventOrientation(QWheelEvent *we) { + if (std::abs(we->angleDelta().x()) < std::abs(we->angleDelta().y())) + return Qt::Vertical; + else + return Qt::Horizontal; +} +inline int wheelEventDelta(QWheelEvent *we) { + if(wheelEventOrientation(we) == Qt::Vertical) + return we->angleDelta().y(); + else + return we->angleDelta().x(); +} +inline QPoint wheelEventPos(QWheelEvent *we) { + return we->position().toPoint(); +} +#else +#define Qt_MiddleButton Qt::MidButton +inline Qt::Orientation wheelEventOrientation(QWheelEvent *we) { + return we->orientation(); +} +inline int wheelEventDelta(QWheelEvent *we) { + return we->delta(); +} +inline QPoint wheelEventPos(QWheelEvent *we) { + return we->pos(); +} + +#endif + + //Static and global first static GuiReceiver *guiMainThread = NULL; static int parameterSystemC = 1; @@ -1579,7 +1611,9 @@ CvWinProperties::CvWinProperties(QString name_paraWindow, QObject* /*parent*/) myLayout->setObjectName(QString::fromUtf8("boxLayout")); myLayout->setContentsMargins(0, 0, 0, 0); myLayout->setSpacing(0); +#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) myLayout->setMargin(0); +#endif myLayout->setSizeConstraint(QLayout::SetFixedSize); setLayout(myLayout); @@ -1957,7 +1991,9 @@ void CvWindow::createBarLayout() myBarLayout->setObjectName(QString::fromUtf8("barLayout")); myBarLayout->setContentsMargins(0, 0, 0, 0); myBarLayout->setSpacing(0); +#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) myBarLayout->setMargin(0); +#endif } @@ -1967,7 +2003,9 @@ void CvWindow::createGlobalLayout() myGlobalLayout->setObjectName(QString::fromUtf8("boxLayout")); myGlobalLayout->setContentsMargins(0, 0, 0, 0); myGlobalLayout->setSpacing(0); +#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) myGlobalLayout->setMargin(0); +#endif setMinimumSize(1, 1); if (param_flags == CV_WINDOW_AUTOSIZE) @@ -2205,7 +2243,7 @@ void CvWindow::icvLoadControlPanel() } if (t->type == type_CvButtonbar) { - int subsize = settings.beginReadArray(QString("buttonbar")+i); + int subsize = settings.beginReadArray(QString("buttonbar%1").arg(i)); if ( subsize == ((CvButtonbar*)t)->layout()->count() ) icvLoadButtonbar((CvButtonbar*)t,&settings); @@ -2236,7 +2274,7 @@ void CvWindow::icvSaveControlPanel() } if (t->type == type_CvButtonbar) { - settings.beginWriteArray(QString("buttonbar")+i); + settings.beginWriteArray(QString("buttonbar%1").arg(i)); icvSaveButtonbar((CvButtonbar*)t,&settings); settings.endArray(); } @@ -2396,14 +2434,14 @@ void OCVViewPort::icvmouseHandler(QMouseEvent* evnt, type_mouse_event category, flags |= CV_EVENT_FLAG_LBUTTON; if(buttons & Qt::RightButton) flags |= CV_EVENT_FLAG_RBUTTON; - if(buttons & Qt::MidButton) + if(buttons & Qt_MiddleButton) flags |= CV_EVENT_FLAG_MBUTTON; if (cv_event == -1) { if (category == mouse_wheel) { QWheelEvent *we = (QWheelEvent *) evnt; - cv_event = ((we->orientation() == Qt::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL); - flags |= (we->delta() & 0xffff)<<16; + cv_event = ((wheelEventOrientation(we) == Qt::Vertical) ? CV_EVENT_MOUSEWHEEL : CV_EVENT_MOUSEHWHEEL); + flags |= (wheelEventDelta(we) & 0xffff)<<16; return; } switch(evnt->button()) @@ -2416,7 +2454,7 @@ void OCVViewPort::icvmouseHandler(QMouseEvent* evnt, type_mouse_event category, cv_event = tableMouseButtons[category][1]; flags |= CV_EVENT_FLAG_RBUTTON; break; - case Qt::MidButton: + case Qt_MiddleButton: cv_event = tableMouseButtons[category][2]; flags |= CV_EVENT_FLAG_MBUTTON; break; @@ -2772,7 +2810,7 @@ void DefaultViewPort::wheelEvent(QWheelEvent* evnt) { icvmouseEvent((QMouseEvent *)evnt, mouse_wheel); - scaleView(evnt->delta() / 240.0, evnt->pos()); + scaleView(wheelEventDelta(evnt) / 240.0, wheelEventPos(evnt)); viewport()->update(); QWidget::wheelEvent(evnt); From f11f2bfb56e4bbeb6a05ec4112adc375ea8fc515 Mon Sep 17 00:00:00 2001 From: keroiber <39693294+keroiber@users.noreply.github.com> Date: Mon, 4 Oct 2021 18:51:49 +0200 Subject: [PATCH 3/3] Merge pull request #20743 from keroiber:prefix_js_function_bindings_with_namespace * Prefix global javascript functions with sub-namespaces * js: handle 'namespace_prefix_override', update filtering - avoid functions override with same name but different namespace Co-authored-by: Alexander Alekhin --- modules/js/generator/CMakeLists.txt | 1 + modules/js/generator/embindgen.py | 51 +++++++++++++++++++++++------ platforms/js/opencv_js.config.py | 24 ++++++++++++-- 3 files changed, 63 insertions(+), 13 deletions(-) diff --git a/modules/js/generator/CMakeLists.txt b/modules/js/generator/CMakeLists.txt index 7a53429651..3d66df154f 100644 --- a/modules/js/generator/CMakeLists.txt +++ b/modules/js/generator/CMakeLists.txt @@ -60,6 +60,7 @@ add_custom_command( ${JS_SOURCE_DIR}/src/core_bindings.cpp ${CMAKE_CURRENT_SOURCE_DIR}/embindgen.py ${CMAKE_CURRENT_SOURCE_DIR}/templates.py + "${OPENCV_JS_WHITELIST_FILE}" ${scripts_hdr_parser} #(not needed - generated by CMake) ${CMAKE_CURRENT_BINARY_DIR}/headers.txt ${opencv_hdrs} diff --git a/modules/js/generator/embindgen.py b/modules/js/generator/embindgen.py index dc7a001df1..7eb20c9861 100644 --- a/modules/js/generator/embindgen.py +++ b/modules/js/generator/embindgen.py @@ -104,6 +104,9 @@ def makeWhiteList(module_list): return wl white_list = None +namespace_prefix_override = { + 'dnn' : '' +} # Features to be exported export_enums = False @@ -271,6 +274,8 @@ class FuncVariant(object): class FuncInfo(object): def __init__(self, class_name, name, cname, namespace, isconstructor): + self.name_id = '_'.join([namespace] + ([class_name] if class_name else []) + [name]) # unique id for dict key + self.class_name = class_name self.name = name self.cname = cname @@ -295,9 +300,9 @@ class JSWrapperGenerator(object): self.bindings = [] self.wrapper_funcs = [] - self.classes = {} + self.classes = {} # FIXIT 'classes' should belong to 'namespaces' self.namespaces = {} - self.enums = {} + self.enums = {} # FIXIT 'enums' should belong to 'namespaces' self.parser = hdr_parser.CppHeaderParser() self.class_idx = 0 @@ -419,7 +424,8 @@ class JSWrapperGenerator(object): else: func_map = self.namespaces.setdefault(namespace, Namespace()).funcs - func = func_map.setdefault(name, FuncInfo(class_name, name, cpp_name, namespace, is_constructor)) + fi = FuncInfo(class_name, name, cpp_name, namespace, is_constructor) + func = func_map.setdefault(fi.name_id, fi) variant = FuncVariant(class_name, name, decl, is_constructor, is_class_method, is_const_method, is_virtual_method, is_pure_virtual_method, ref_return, const_return) @@ -430,7 +436,7 @@ class JSWrapperGenerator(object): f.write(buf.getvalue()) f.close() - def gen_function_binding_with_wrapper(self, func, class_info): + def gen_function_binding_with_wrapper(self, func, ns_name, class_info): binding_text = None wrapper_func_text = None @@ -488,8 +494,23 @@ class JSWrapperGenerator(object): # Wrapper function - wrap_func_name = (func.class_name+"_" if class_info != None else "") + func.name.split("::")[-1] + "_wrapper" - js_func_name = func.name + if ns_name != None and ns_name != "cv": + ns_parts = ns_name.split(".") + if ns_parts[0] == "cv": + ns_parts = ns_parts[1:] + ns_part = "_".join(ns_parts) + "_" + ns_id = '_'.join(ns_parts) + ns_prefix = namespace_prefix_override.get(ns_id, ns_id) + if ns_prefix: + ns_prefix = ns_prefix + '_' + else: + ns_prefix = '' + if class_info == None: + js_func_name = ns_prefix + func.name + wrap_func_name = js_func_name + "_wrapper" + else: + wrap_func_name = ns_prefix + func.class_name + "_" + func.name + "_wrapper" + js_func_name = func.name # TODO: Name functions based wrap directives or based on arguments list if index > 0: @@ -740,12 +761,22 @@ class JSWrapperGenerator(object): # step 2: generate bindings # Global functions for ns_name, ns in sorted(self.namespaces.items()): - if ns_name.split('.')[0] != 'cv': + ns_parts = ns_name.split('.') + if ns_parts[0] != 'cv': + print('Ignore namespace: {}'.format(ns_name)) continue - for name, func in sorted(ns.funcs.items()): + else: + ns_parts = ns_parts[1:] + ns_id = '_'.join(ns_parts) + ns_prefix = namespace_prefix_override.get(ns_id, ns_id) + for name_id, func in sorted(ns.funcs.items()): + name = func.name + if ns_prefix: + name = ns_prefix + '_' + name if name in ignore_list: continue if not name in white_list['']: + #print('Not in whitelist: "{}" from ns={}'.format(name, ns_name)) continue ext_cnst = False @@ -769,7 +800,7 @@ class JSWrapperGenerator(object): continue if with_wrapped_functions: - binding, wrapper = self.gen_function_binding_with_wrapper(func, class_info=None) + binding, wrapper = self.gen_function_binding_with_wrapper(func, ns_name, class_info=None) self.bindings += binding self.wrapper_funcs += wrapper else: @@ -802,7 +833,7 @@ class JSWrapperGenerator(object): class_bindings.append(constructor_template.substitute(signature=', '.join(args))) else: if with_wrapped_functions and (len(method.variants) > 1 or len(method.variants[0].args)>0 or "String" in method.variants[0].rettype): - binding, wrapper = self.gen_function_binding_with_wrapper(method, class_info=class_info) + binding, wrapper = self.gen_function_binding_with_wrapper(method, None, class_info=class_info) self.wrapper_funcs = self.wrapper_funcs + wrapper class_bindings = class_bindings + binding else: diff --git a/platforms/js/opencv_js.config.py b/platforms/js/opencv_js.config.py index 3e09805cd3..05d2883b78 100644 --- a/platforms/js/opencv_js.config.py +++ b/platforms/js/opencv_js.config.py @@ -55,8 +55,26 @@ features2d = {'Feature2D': ['detect', 'compute', 'detectAndCompute', 'descriptor 'BFMatcher': ['isMaskSupported', 'create'], '': ['drawKeypoints', 'drawMatches', 'drawMatchesKnn']} -calib3d = {'': ['findHomography', 'calibrateCameraExtended', 'drawFrameAxes', 'estimateAffine2D', \ - 'getDefaultNewCameraMatrix', 'initUndistortRectifyMap', 'Rodrigues', \ - 'solvePnP', 'solvePnPRansac', 'solvePnPRefineLM']} +calib3d = { + '': [ + 'findHomography', + 'calibrateCameraExtended', + 'drawFrameAxes', + 'estimateAffine2D', + 'getDefaultNewCameraMatrix', + 'initUndistortRectifyMap', + 'Rodrigues', + 'solvePnP', + 'solvePnPRansac', + 'solvePnPRefineLM', + 'projectPoints', + + # cv::fisheye namespace + 'fisheye_initUndistortRectifyMap', + 'fisheye_projectPoints', + ], +} white_list = makeWhiteList([core, imgproc, objdetect, video, dnn, features2d, calib3d]) + +# namespace_prefix_override['dnn'] = '' # compatibility stuff (enabled by default)