From edc5518f6869fd99bc38f59ae78e9cd4a5a606d2 Mon Sep 17 00:00:00 2001 From: Dizhenin Vlad <39303687+SimpleVlad@users.noreply.github.com> Date: Thu, 31 Oct 2019 22:09:33 +0300 Subject: [PATCH] Merge pull request #15608 from SimpleVlad:3.4 * Add flags for build js * Add poi.json * Rebase whitelist into JSON file * Rework generator of white_list * Fix small typos * Transfer opencv_js.josn in opencv_js.config.py * Edit OPENCV_JS_WHITELIST * Write comment * Add description * Fix typos in desc * flag's append deleeted * Fix whitespace * variable deleted * fix comment on lines 229 and 235 --- modules/js/src/embindgen.py | 56 ++------------------------------ platforms/js/build_js.py | 14 ++++++++ platforms/js/opencv_js.config.py | 52 +++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 53 deletions(-) create mode 100644 platforms/js/opencv_js.config.py diff --git a/modules/js/src/embindgen.py b/modules/js/src/embindgen.py index ea5a939903..0ec4488946 100644 --- a/modules/js/src/embindgen.py +++ b/modules/js/src/embindgen.py @@ -93,58 +93,6 @@ ignore_list = ['locate', #int& 'meanShift' #Rect& ] -# Classes and methods whitelist -core = {'': ['absdiff', 'add', 'addWeighted', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'cartToPolar',\ - 'compare', 'convertScaleAbs', 'copyMakeBorder', 'countNonZero', 'determinant', 'dft', 'divide', 'eigen', \ - 'exp', 'flip', 'getOptimalDFTSize','gemm', 'hconcat', 'inRange', 'invert', 'kmeans', 'log', 'magnitude', \ - 'max', 'mean', 'meanStdDev', 'merge', 'min', 'minMaxLoc', 'mixChannels', 'multiply', 'norm', 'normalize', \ - 'perspectiveTransform', 'polarToCart', 'pow', 'randn', 'randu', 'reduce', 'repeat', 'rotate', 'setIdentity', 'setRNGSeed', \ - 'solve', 'solvePoly', 'split', 'sqrt', 'subtract', 'trace', 'transform', 'transpose', 'vconcat'], - 'Algorithm': []} - -imgproc = {'': ['Canny', 'GaussianBlur', 'Laplacian', 'HoughLines', 'HoughLinesP', 'HoughCircles', 'Scharr','Sobel', \ - 'adaptiveThreshold','approxPolyDP','arcLength','bilateralFilter','blur','boundingRect','boxFilter',\ - 'calcBackProject','calcHist','circle','compareHist','connectedComponents','connectedComponentsWithStats', \ - 'contourArea', 'convexHull', 'convexityDefects', 'cornerHarris','cornerMinEigenVal','createCLAHE', \ - 'createLineSegmentDetector','cvtColor','demosaicing','dilate', 'distanceTransform','distanceTransformWithLabels', \ - 'drawContours','ellipse','ellipse2Poly','equalizeHist','erode', 'filter2D', 'findContours','fitEllipse', \ - 'fitLine', 'floodFill','getAffineTransform', 'getPerspectiveTransform', 'getRotationMatrix2D', 'getStructuringElement', \ - 'goodFeaturesToTrack','grabCut','initUndistortRectifyMap', 'integral','integral2', 'isContourConvex', 'line', \ - 'matchShapes', 'matchTemplate','medianBlur', 'minAreaRect', 'minEnclosingCircle', 'moments', 'morphologyEx', \ - 'pointPolygonTest', 'putText','pyrDown','pyrUp','rectangle','remap', 'resize','sepFilter2D','threshold', \ - 'undistort','warpAffine','warpPerspective','warpPolar','watershed', \ - 'fillPoly', 'fillConvexPoly'], - 'CLAHE': ['apply', 'collectGarbage', 'getClipLimit', 'getTilesGridSize', 'setClipLimit', 'setTilesGridSize']} - -objdetect = {'': ['groupRectangles'], - 'HOGDescriptor': ['load', 'HOGDescriptor', 'getDefaultPeopleDetector', 'getDaimlerPeopleDetector', 'setSVMDetector', 'detectMultiScale'], - 'CascadeClassifier': ['load', 'detectMultiScale2', 'CascadeClassifier', 'detectMultiScale3', 'empty', 'detectMultiScale']} - -video = {'': ['CamShift', 'calcOpticalFlowFarneback', 'calcOpticalFlowPyrLK', 'createBackgroundSubtractorMOG2', \ - 'findTransformECC', 'meanShift'], - 'BackgroundSubtractorMOG2': ['BackgroundSubtractorMOG2', 'apply'], - 'BackgroundSubtractor': ['apply', 'getBackgroundImage']} - -dnn = {'dnn_Net': ['setInput', 'forward'], - '': ['readNetFromCaffe', 'readNetFromTensorflow', 'readNetFromTorch', 'readNetFromDarknet', - 'readNetFromONNX', 'readNet', 'blobFromImage']} - -features2d = {'Feature2D': ['detect', 'compute', 'detectAndCompute', 'descriptorSize', 'descriptorType', 'defaultNorm', 'empty', 'getDefaultName'], - 'BRISK': ['create', 'getDefaultName'], - 'ORB': ['create', 'setMaxFeatures', 'setScaleFactor', 'setNLevels', 'setEdgeThreshold', 'setFirstLevel', 'setWTA_K', 'setScoreType', 'setPatchSize', 'getFastThreshold', 'getDefaultName'], - 'MSER': ['create', 'detectRegions', 'setDelta', 'getDelta', 'setMinArea', 'getMinArea', 'setMaxArea', 'getMaxArea', 'setPass2Only', 'getPass2Only', 'getDefaultName'], - 'FastFeatureDetector': ['create', 'setThreshold', 'getThreshold', 'setNonmaxSuppression', 'getNonmaxSuppression', 'setType', 'getType', 'getDefaultName'], - 'AgastFeatureDetector': ['create', 'setThreshold', 'getThreshold', 'setNonmaxSuppression', 'getNonmaxSuppression', 'setType', 'getType', 'getDefaultName'], - 'GFTTDetector': ['create', 'setMaxFeatures', 'getMaxFeatures', 'setQualityLevel', 'getQualityLevel', 'setMinDistance', 'getMinDistance', 'setBlockSize', 'getBlockSize', 'setHarrisDetector', 'getHarrisDetector', 'setK', 'getK', 'getDefaultName'], - # 'SimpleBlobDetector': ['create'], - 'KAZE': ['create', 'setExtended', 'getExtended', 'setUpright', 'getUpright', 'setThreshold', 'getThreshold', 'setNOctaves', 'getNOctaves', 'setNOctaveLayers', 'getNOctaveLayers', 'setDiffusivity', 'getDiffusivity', 'getDefaultName'], - 'AKAZE': ['create', 'setDescriptorType', 'getDescriptorType', 'setDescriptorSize', 'getDescriptorSize', 'setDescriptorChannels', 'getDescriptorChannels', 'setThreshold', 'getThreshold', 'setNOctaves', 'getNOctaves', 'setNOctaveLayers', 'getNOctaveLayers', 'setDiffusivity', 'getDiffusivity', 'getDefaultName'], - 'DescriptorMatcher': ['add', 'clear', 'empty', 'isMaskSupported', 'train', 'match', 'knnMatch', 'radiusMatch', 'clone', 'create'], - 'BFMatcher': ['isMaskSupported', 'create'], - '': ['drawKeypoints', 'drawMatches', 'drawMatchesKnn']} - -calib3d = {'': ['findHomography', 'estimateAffine2D', 'Rodrigues']} - def makeWhiteList(module_list): wl = {} for m in module_list: @@ -155,7 +103,9 @@ def makeWhiteList(module_list): wl[k] = m[k] return wl -white_list = makeWhiteList([core, imgproc, objdetect, video, dnn, features2d, calib3d]) +white_list = None +exec(open(os.environ["OPENCV_JS_WHITELIST"]).read()) +assert(white_list) # Features to be exported export_enums = False diff --git a/platforms/js/build_js.py b/platforms/js/build_js.py index 3a4612a89a..fbeb1e4fb3 100644 --- a/platforms/js/build_js.py +++ b/platforms/js/build_js.py @@ -138,6 +138,8 @@ class Builder: "-DBUILD_PACKAGE=OFF", "-DBUILD_TESTS=OFF", "-DBUILD_PERF_TESTS=OFF"] + if self.options.cmake_option: + cmd += self.options.cmake_option if self.options.build_doc: cmd.append("-DBUILD_DOCS=ON") else: @@ -178,6 +180,8 @@ class Builder: flags += "-s DISABLE_EXCEPTION_CATCHING=0 " if self.options.simd: flags += "-msimd128 " + if self.options.build_flags: + flags += self.options.build_flags return flags def config(self): @@ -221,12 +225,22 @@ if __name__ == "__main__": parser.add_argument('--skip_config', action="store_true", help="Skip cmake config") parser.add_argument('--config_only', action="store_true", help="Only do cmake config") parser.add_argument('--enable_exception', action="store_true", help="Enable exception handling") + # Use flag --cmake option="-D...=ON" only for one argument, if you would add more changes write new cmake_option flags + parser.add_argument('--cmake_option', action='append', help="Append CMake options") + # Use flag --build_flags="-s USE_PTHREADS=0 -Os" for one and more arguments as in the example + parser.add_argument('--build_flags', help="Append Emscripten build options") parser.add_argument('--build_wasm_intrin_test', default=False, action="store_true", help="Build WASM intrin tests") + # Write a path to modify file like argument of this flag + parser.add_argument('--config', default=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'opencv_js.config.py'), + help="Specify configuration file with own list of exported into JS functions") + args = parser.parse_args() log.basicConfig(format='%(message)s', level=log.DEBUG) log.debug("Args: %s", args) + os.environ["OPENCV_JS_WHITELIST"] = args.config + if args.emscripten_dir is None: log.info("Cannot get Emscripten path, please specify it either by EMSCRIPTEN environment variable or --emscripten_dir option.") sys.exit(-1) diff --git a/platforms/js/opencv_js.config.py b/platforms/js/opencv_js.config.py new file mode 100644 index 0000000000..bcbdcfdf96 --- /dev/null +++ b/platforms/js/opencv_js.config.py @@ -0,0 +1,52 @@ +core = {'': ['absdiff', 'add', 'addWeighted', 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'cartToPolar',\ + 'compare', 'convertScaleAbs', 'copyMakeBorder', 'countNonZero', 'determinant', 'dft', 'divide', 'eigen', \ + 'exp', 'flip', 'getOptimalDFTSize','gemm', 'hconcat', 'inRange', 'invert', 'kmeans', 'log', 'magnitude', \ + 'max', 'mean', 'meanStdDev', 'merge', 'min', 'minMaxLoc', 'mixChannels', 'multiply', 'norm', 'normalize', \ + 'perspectiveTransform', 'polarToCart', 'pow', 'randn', 'randu', 'reduce', 'repeat', 'rotate', 'setIdentity', 'setRNGSeed', \ + 'solve', 'solvePoly', 'split', 'sqrt', 'subtract', 'trace', 'transform', 'transpose', 'vconcat'], + 'Algorithm': []} + +imgproc = {'': ['Canny', 'GaussianBlur', 'Laplacian', 'HoughLines', 'HoughLinesP', 'HoughCircles', 'Scharr','Sobel', \ + 'adaptiveThreshold','approxPolyDP','arcLength','bilateralFilter','blur','boundingRect','boxFilter',\ + 'calcBackProject','calcHist','circle','compareHist','connectedComponents','connectedComponentsWithStats', \ + 'contourArea', 'convexHull', 'convexityDefects', 'cornerHarris','cornerMinEigenVal','createCLAHE', \ + 'createLineSegmentDetector','cvtColor','demosaicing','dilate', 'distanceTransform','distanceTransformWithLabels', \ + 'drawContours','ellipse','ellipse2Poly','equalizeHist','erode', 'filter2D', 'findContours','fitEllipse', \ + 'fitLine', 'floodFill','getAffineTransform', 'getPerspectiveTransform', 'getRotationMatrix2D', 'getStructuringElement', \ + 'goodFeaturesToTrack','grabCut','initUndistortRectifyMap', 'integral','integral2', 'isContourConvex', 'line', \ + 'matchShapes', 'matchTemplate','medianBlur', 'minAreaRect', 'minEnclosingCircle', 'moments', 'morphologyEx', \ + 'pointPolygonTest', 'putText','pyrDown','pyrUp','rectangle','remap', 'resize','sepFilter2D','threshold', \ + 'undistort','warpAffine','warpPerspective','warpPolar','watershed', \ + 'fillPoly', 'fillConvexPoly'], + 'CLAHE': ['apply', 'collectGarbage', 'getClipLimit', 'getTilesGridSize', 'setClipLimit', 'setTilesGridSize']} + +objdetect = {'': ['groupRectangles'], + 'HOGDescriptor': ['load', 'HOGDescriptor', 'getDefaultPeopleDetector', 'getDaimlerPeopleDetector', 'setSVMDetector', 'detectMultiScale'], + 'CascadeClassifier': ['load', 'detectMultiScale2', 'CascadeClassifier', 'detectMultiScale3', 'empty', 'detectMultiScale']} + +video = {'': ['CamShift', 'calcOpticalFlowFarneback', 'calcOpticalFlowPyrLK', 'createBackgroundSubtractorMOG2', \ + 'findTransformECC', 'meanShift'], + 'BackgroundSubtractorMOG2': ['BackgroundSubtractorMOG2', 'apply'], + 'BackgroundSubtractor': ['apply', 'getBackgroundImage']} + +dnn = {'dnn_Net': ['setInput', 'forward'], + '': ['readNetFromCaffe', 'readNetFromTensorflow', 'readNetFromTorch', 'readNetFromDarknet', + 'readNetFromONNX', 'readNet', 'blobFromImage']} + +features2d = {'Feature2D': ['detect', 'compute', 'detectAndCompute', 'descriptorSize', 'descriptorType', 'defaultNorm', 'empty', 'getDefaultName'], + 'BRISK': ['create', 'getDefaultName'], + 'ORB': ['create', 'setMaxFeatures', 'setScaleFactor', 'setNLevels', 'setEdgeThreshold', 'setFirstLevel', 'setWTA_K', 'setScoreType', 'setPatchSize', 'getFastThreshold', 'getDefaultName'], + 'MSER': ['create', 'detectRegions', 'setDelta', 'getDelta', 'setMinArea', 'getMinArea', 'setMaxArea', 'getMaxArea', 'setPass2Only', 'getPass2Only', 'getDefaultName'], + 'FastFeatureDetector': ['create', 'setThreshold', 'getThreshold', 'setNonmaxSuppression', 'getNonmaxSuppression', 'setType', 'getType', 'getDefaultName'], + 'AgastFeatureDetector': ['create', 'setThreshold', 'getThreshold', 'setNonmaxSuppression', 'getNonmaxSuppression', 'setType', 'getType', 'getDefaultName'], + 'GFTTDetector': ['create', 'setMaxFeatures', 'getMaxFeatures', 'setQualityLevel', 'getQualityLevel', 'setMinDistance', 'getMinDistance', 'setBlockSize', 'getBlockSize', 'setHarrisDetector', 'getHarrisDetector', 'setK', 'getK', 'getDefaultName'], + # 'SimpleBlobDetector': ['create'], + 'KAZE': ['create', 'setExtended', 'getExtended', 'setUpright', 'getUpright', 'setThreshold', 'getThreshold', 'setNOctaves', 'getNOctaves', 'setNOctaveLayers', 'getNOctaveLayers', 'setDiffusivity', 'getDiffusivity', 'getDefaultName'], + 'AKAZE': ['create', 'setDescriptorType', 'getDescriptorType', 'setDescriptorSize', 'getDescriptorSize', 'setDescriptorChannels', 'getDescriptorChannels', 'setThreshold', 'getThreshold', 'setNOctaves', 'getNOctaves', 'setNOctaveLayers', 'getNOctaveLayers', 'setDiffusivity', 'getDiffusivity', 'getDefaultName'], + 'DescriptorMatcher': ['add', 'clear', 'empty', 'isMaskSupported', 'train', 'match', 'knnMatch', 'radiusMatch', 'clone', 'create'], + 'BFMatcher': ['isMaskSupported', 'create'], + '': ['drawKeypoints', 'drawMatches', 'drawMatchesKnn']} + +calib3d = {'': ['findHomography', 'estimateAffine2D', 'Rodrigues']} + +white_list = makeWhiteList([core, imgproc, objdetect, video, dnn, features2d, calib3d]) \ No newline at end of file