opencv/platforms/js/build_js.py

275 lines
10 KiB
Python
Raw Normal View History

Merge pull request #9466 from huningxin:js GSoC 2017: Improve and Extend the JavaScript Bindings for OpenCV (#9466) * Initial support for build with emscripten mkdir build_js cd build_js cmake -D CMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emsdk-portable/emscripten/master/cmake/Modules/Platform/Emscripten.cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. * Add js module The output is build/bin/opencv_js.js * Fix opencv2/calib3d.hpp not found issue * Add module name Usage: var cv = cv(); * Add total memory as 128MB and allow growth * Add compilation flags for emscripten * Use EMSCRIPTEN build target * Disable js module for non emscripten build * Bind the preload file path to root Usage: face_cascade.load('haarcascade_frontalface_default.xml'); * add test folder * fix test files * Copy js module test to bin * Support to run tests on Node.js Fix tests to import cv Module when runtime is node. Add tests.js to use qunit to auto run tests. Modify umd wrapper to support Module is not defined. Usage: node tests.js * Support UMD and file system Wrap the opencv_js.js to opencv.js by UMD wrapper Use emscripten file system API to load files instead of generating data file or embedding them. It supports both browser and node.js usages. * Fix incorrect module name in tests * Add package.json to add dependence of qunit * Add js_tutorials folder and a intro page of opencv.js Enable BUILD_DOCS in CMakeLists.txt. Add new folder of js_tutorials in folder opencv/doc. Imitate the tutorials of OpenCV-Python to create a intro page of opencv.js and a setup guide * Import and use binding gen from opencvjs project * Modify the embindgen.py to pass the build and test * Add classes and functions white list * Consolidate hdr_parser.py (#31) Use hdr_parser.py of python module Add js flag to support js binding generator. * Use emscripten::vecFromJSArray for input vector param Fix part of #23 * Fix test cases after #34 Fix #39 * Expose groupRectangles and CascadeClassifier.empty * Add js highgui tutorials add tutorials of imread&imshow and createTrackbar in doc/js_tutorials/js_gui folder add interactive tutorial webpage for imread&imshow and createTrackbar in doc/js_tutorials/js_interactive_tutorials folder, and some images needed. change doc/CMakeLists.txt to copy the interactive tutorial webpage and opencv.js to the tutorials' destination folder * rm useless annotation in doc/CMakeLists.txt * fix some nonstandard indentation and space * add check if canvas is valid * Expose BackgroundSubtractorMOG2 Fix #43 * Fix build of js doc Limit copy_js_interactive_tutorials for doxygen build Add dep to opencv.js Fix #53 * Implement cv.imread & cv.imshow and insert interactive pages in tutorials (#55) * add helper.js * delete ALL in add target copy_js_interactive_tutorials to avoid dependence error * Insert interactive pages in tutorials insert the old interactive pages in markdown by using \htmlonly and \endhtmlonly command. delete the useless interactive page rename js_interactive_tutorials to js_assets to put some images needed in * fix the depends of the target doxygen add opencv.js to depends and delete the useless target of copy_js_assets * change filename helper.js to helpers.js * disable button or trankbar before opencv.js is ready * Expose CV_64F Fix #65 * improve cv.imshow to display different types as native imshow * add utils.js to reuse functions and update tutorials * Make doxygen depend on bin/opencv.js * Fix memory issue of matFromArray Fix #37 * Merge pull request from ganwenyao/tutorial_18 * Add notes for ganwenyao/tutorial_18 * Modifying for ganwenyao/tutorial_18 * Change Mat constructor with data to 5 parameters * Mat supports constructor with Scalar Fix #60 * update cv.imread cause the memory issue of matFromArray has been fixed * fix canvas name and default input image * Expose cv::Moments Fix #85 * Add -Wno-missing-prototypes for emscripten build * fix canvas name * add tutorial of video input and output * Expose enums as emscripten consts Fix #72 * update the tutorial to use Mat constructor with Scalar and change lena.jpg * Exclude cv::Mat for vecFromJSArray Fix #82 * Add unit tests for cv.moments * Fix the unit tests. * add checkbox and stop button * add adapter.js to make sure compatibility fo video tutorials * Support default parameters with function overloading * modify enums to constants * Use https URL for MathJax.js Fix #109 * Comment out the debug print in embindgen.py * Expose RotatedRect Fix #96 * replace enum with constants and improve onload function * delete some useless paras cause #105 fixed this * Modify const name * Modify Contour Properties * tutorials for imgprc2 and objdec * Expose more functions for img proc tutorials Fix #76 * Expose polylines for video analysis tutorial Fix #121 * Expose constants for default parameters of img proc tutorials Fix #122 * Fix wrong parameter types of Mat.copyTo Fix #87 * Support default parameters of mat.convertTo Fix #123 * Support default parameters for external constructors Fix #131 * Revert "Expose polylines for video analysis tutorial" This reverts commit 3ce7615652e510d30e3c0014706ac38c98883189. Fix #121 * Support cv.minMaxLoc Fix #127 * Expose cv.minEnclosingCircle Fix #126 * Add video analysis tutorials add three video tutorials, Meanshift and Camshift, Optical Flow Background Subtraction add cup.mp4 and box.mp4 for demo in tutorials * improve image processing tutorials * repalce console.warn with throw to throw exception * add try-catch to throw exception in code demo * Change mat.size() return value to JS Array object Fix #140 * add a note about different channels order between canvas and native opencv * add a note about how to capture video from video files * Binding cv.Scalar to JS array Fix #147 * Add JS cv.Scalar object into helpers.js * Update Install OpenCV-JavaScript tutorial page Fix #44 * Update the OpenCV-JavaScript introduction page Fix #44 * add cv.VideoCapture and read() function * set the size of the hidden canvas same as the video * Add Using OpenCV-JavaScript tutorial page Fix #44 * fix some bad code style * Update tutorials after 8/2 sync meeting Changes include: - Use OpenCV.js name instead of OpenCV-JavaScript - Put using OpenCV.js ahead of build OpenCV.js - Refine usage and introduction page - Muted the video in tutorials * Fix a typo in introduction page * use cv.VideoCapture and its read() function to read video * replace OpenCV-JavaScript with OpenCV.js * Use onload of async script in js_usage tutorial * add more info about mat.data * Change Size to value_object * Integrate Moh and Sajjad's editing into introduction page * Change Point to value_object * Change Rect to value_object with helper object * Add helper objects for Point and Size * Change RotatedRect to value_object with helpers * Change MinMaxLoc and Circle to value_object * Change TermCriteria to value_object * Fix core_bindings.cpp for MinMaxLoc and Circle * Remove unused types * Change meanShift and CamShift to return Rect * Change methods of RotatedRect to static * Change mat.data from methods to property Fix #75 and #77 * support img id and element in cv.imread * Change mat.size to property and add mat.step Fix #163 * Add matFromArray and matFromImageData as JS helpers Fix #79, #78 * Lower camel case for Mat element getters Fix #81 * Mat.getRoiRect and tests Fix #86 * Support type for Mat.ptr Fix #83 * Name changing of Mat element getters 'getUcharAt` -> 'ucharAt' * fix code style and args names * Fix helpers.js due to cv.Mat API update * Fix opencv.js usage tutorial * Fix a typo of js_setup * Change Moments to value_object * Add Range as value_object Fix #171 * Support Mat.diag and Mat.isContinous Fix #84 and #89 * Support Mat.setTo Fix #88 * Apply edits to js_intro * Apply edits to js_usage * Apply edits to js_setup * update tutorials to apply data type change * Modify tutorials * add core tutorials * delete MatVector elements and delete useless set operation * add tutorials_objdec_camera * Add instructions for WebAssembly * apply tech writer's feedbacks into tutorials * Organize white list by modules * Change size to method and bind to MatExpr.size() Fix #177 * improve tutorials * Modify core tutorials * add params list and explanations for OpenCV.js functions * remove face_profile from Face Detection in Video Capture * Add demos link * Change Gui to GUI * Update js_intro based on Moh and Sajjad's edits * Fixup for 3.3.0 rebase * Update js_intro per Moh's suggestion * Update contributors list per Moh's idea * add adapter.js in video_display tutorial * Change Mat.getRoiRect to Mat.roi Fix #194 * Remove unnecessary files for test Fix #192 * Licenses updated to UC BSD 3-Clause * Apply OpenCV coding style for C++ files * Add OpenCV license for python and js files * Fix coding style issue in helpers.js * Remove unused test_commons.js * Fix coding style of test_imgproc.js * Fix coding style of test_mat.js * Fix space before semicolon * Fix coding style of test_objdetect.js * Fix coding style of tests.js * Fix coding style of test_utils.js * Fix coding style of test_video.js * Fix failures of node.js tests * Add eslint rule config and fix eslint errors * Add eslint config for js/src and fix eslint errors * Clean up the opencv.js dependencies Fix #186 * Fix build issue for python generator * Fix doxygen buildbot failure * delete trailing whitespace, blank line at EOF and replace tab with space * Fix tutorial_js_root reference issue for non opencv.js build * replace the file with small size * Initial commit of build_js.py * Move the js build configurations to build script * Add wasm build support * Update OpenCV.js build tutorial by using script * Fix global var issue in tests * Add a README.md for build_js.py * Copy the haar cascade files from data dir for tutorials * Not use memory init file * Disable debug print for modules/js/CMakeLists.txt * Check files when build done * Fix image name in js_gradients tutorial * Fix image load issue in js_trackbar tutorial * Find the opencv source directory via relative path by default * Make the cmake args based on build_doc option * Fix a typo in js_setup.markdown * Fix make failure issue on config generated by build_js.py * Eliminate js branch of hdr_parser.py * Extract examples from js_basic_ops tutorial * Fix coding style of utils.js * Improve examples error handling Handle: 1. opencv.js loading errors 2. script errors (Error) 3. cv::Exception Fix #217 * Add enable_exception option into build_js.py * Support print exception for exception catching disabled build * Extract example from js_usage tutorial * Avoid copying .eslintrc.json when building doc Fix #223 * Revert to use onload as opencv.js ready event * Use 4 spaces indention for js examples * embed html in tutorials with iframe tag * Revert to use onload as opencv.js ready event * Extract examples from js_video_display tutorial * Implement Utils object * modify core imgprc and face_detection tutorials * Fix examples of js_gui tutorials * Fix coding style of utils.js * Modify tutorials * Extract example from js_face_detection_camera tutorial * Disable new-cap check in eslint * Extract examples from js_meanshift tutorial * Extract examples from video tutorials * Remove new-cap declaration and update grammer in comments * Change textarea width to 100 to align with eslint config * Fix printError issue when opencv.js loading fails * Remove BUILD_opencv_js dependency for doc build Fix #213 * Expose cv::getBuildInformation * Dump opencv build info when opencv.js loaded for live examples * Make the button to stand out in js live examples Fix #235 * Style for disabled button * Add js_imgproc_camera.html example * Fix coding style of imgproc_camera example * Add js_imgproc_camera tutorial * Remove link to opencv.js demos * doc: copy opencv.js on build, use absolute paths for assets * doc: reuse existed file box.mp4
2017-09-25 21:52:07 +08:00
#!/usr/bin/env python
import os, sys, subprocess, argparse, shutil, glob, re, multiprocessing
import logging as log
class Fail(Exception):
def __init__(self, text=None):
self.t = text
def __str__(self):
return "ERROR" if self.t is None else self.t
def execute(cmd, shell=False):
try:
log.info("Executing: %s" % cmd)
retcode = subprocess.call(cmd, shell=shell)
if retcode < 0:
2018-05-03 13:47:34 +08:00
raise Fail("Child was terminated by signal: %s" % -retcode)
Merge pull request #9466 from huningxin:js GSoC 2017: Improve and Extend the JavaScript Bindings for OpenCV (#9466) * Initial support for build with emscripten mkdir build_js cd build_js cmake -D CMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emsdk-portable/emscripten/master/cmake/Modules/Platform/Emscripten.cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. * Add js module The output is build/bin/opencv_js.js * Fix opencv2/calib3d.hpp not found issue * Add module name Usage: var cv = cv(); * Add total memory as 128MB and allow growth * Add compilation flags for emscripten * Use EMSCRIPTEN build target * Disable js module for non emscripten build * Bind the preload file path to root Usage: face_cascade.load('haarcascade_frontalface_default.xml'); * add test folder * fix test files * Copy js module test to bin * Support to run tests on Node.js Fix tests to import cv Module when runtime is node. Add tests.js to use qunit to auto run tests. Modify umd wrapper to support Module is not defined. Usage: node tests.js * Support UMD and file system Wrap the opencv_js.js to opencv.js by UMD wrapper Use emscripten file system API to load files instead of generating data file or embedding them. It supports both browser and node.js usages. * Fix incorrect module name in tests * Add package.json to add dependence of qunit * Add js_tutorials folder and a intro page of opencv.js Enable BUILD_DOCS in CMakeLists.txt. Add new folder of js_tutorials in folder opencv/doc. Imitate the tutorials of OpenCV-Python to create a intro page of opencv.js and a setup guide * Import and use binding gen from opencvjs project * Modify the embindgen.py to pass the build and test * Add classes and functions white list * Consolidate hdr_parser.py (#31) Use hdr_parser.py of python module Add js flag to support js binding generator. * Use emscripten::vecFromJSArray for input vector param Fix part of #23 * Fix test cases after #34 Fix #39 * Expose groupRectangles and CascadeClassifier.empty * Add js highgui tutorials add tutorials of imread&imshow and createTrackbar in doc/js_tutorials/js_gui folder add interactive tutorial webpage for imread&imshow and createTrackbar in doc/js_tutorials/js_interactive_tutorials folder, and some images needed. change doc/CMakeLists.txt to copy the interactive tutorial webpage and opencv.js to the tutorials' destination folder * rm useless annotation in doc/CMakeLists.txt * fix some nonstandard indentation and space * add check if canvas is valid * Expose BackgroundSubtractorMOG2 Fix #43 * Fix build of js doc Limit copy_js_interactive_tutorials for doxygen build Add dep to opencv.js Fix #53 * Implement cv.imread & cv.imshow and insert interactive pages in tutorials (#55) * add helper.js * delete ALL in add target copy_js_interactive_tutorials to avoid dependence error * Insert interactive pages in tutorials insert the old interactive pages in markdown by using \htmlonly and \endhtmlonly command. delete the useless interactive page rename js_interactive_tutorials to js_assets to put some images needed in * fix the depends of the target doxygen add opencv.js to depends and delete the useless target of copy_js_assets * change filename helper.js to helpers.js * disable button or trankbar before opencv.js is ready * Expose CV_64F Fix #65 * improve cv.imshow to display different types as native imshow * add utils.js to reuse functions and update tutorials * Make doxygen depend on bin/opencv.js * Fix memory issue of matFromArray Fix #37 * Merge pull request from ganwenyao/tutorial_18 * Add notes for ganwenyao/tutorial_18 * Modifying for ganwenyao/tutorial_18 * Change Mat constructor with data to 5 parameters * Mat supports constructor with Scalar Fix #60 * update cv.imread cause the memory issue of matFromArray has been fixed * fix canvas name and default input image * Expose cv::Moments Fix #85 * Add -Wno-missing-prototypes for emscripten build * fix canvas name * add tutorial of video input and output * Expose enums as emscripten consts Fix #72 * update the tutorial to use Mat constructor with Scalar and change lena.jpg * Exclude cv::Mat for vecFromJSArray Fix #82 * Add unit tests for cv.moments * Fix the unit tests. * add checkbox and stop button * add adapter.js to make sure compatibility fo video tutorials * Support default parameters with function overloading * modify enums to constants * Use https URL for MathJax.js Fix #109 * Comment out the debug print in embindgen.py * Expose RotatedRect Fix #96 * replace enum with constants and improve onload function * delete some useless paras cause #105 fixed this * Modify const name * Modify Contour Properties * tutorials for imgprc2 and objdec * Expose more functions for img proc tutorials Fix #76 * Expose polylines for video analysis tutorial Fix #121 * Expose constants for default parameters of img proc tutorials Fix #122 * Fix wrong parameter types of Mat.copyTo Fix #87 * Support default parameters of mat.convertTo Fix #123 * Support default parameters for external constructors Fix #131 * Revert "Expose polylines for video analysis tutorial" This reverts commit 3ce7615652e510d30e3c0014706ac38c98883189. Fix #121 * Support cv.minMaxLoc Fix #127 * Expose cv.minEnclosingCircle Fix #126 * Add video analysis tutorials add three video tutorials, Meanshift and Camshift, Optical Flow Background Subtraction add cup.mp4 and box.mp4 for demo in tutorials * improve image processing tutorials * repalce console.warn with throw to throw exception * add try-catch to throw exception in code demo * Change mat.size() return value to JS Array object Fix #140 * add a note about different channels order between canvas and native opencv * add a note about how to capture video from video files * Binding cv.Scalar to JS array Fix #147 * Add JS cv.Scalar object into helpers.js * Update Install OpenCV-JavaScript tutorial page Fix #44 * Update the OpenCV-JavaScript introduction page Fix #44 * add cv.VideoCapture and read() function * set the size of the hidden canvas same as the video * Add Using OpenCV-JavaScript tutorial page Fix #44 * fix some bad code style * Update tutorials after 8/2 sync meeting Changes include: - Use OpenCV.js name instead of OpenCV-JavaScript - Put using OpenCV.js ahead of build OpenCV.js - Refine usage and introduction page - Muted the video in tutorials * Fix a typo in introduction page * use cv.VideoCapture and its read() function to read video * replace OpenCV-JavaScript with OpenCV.js * Use onload of async script in js_usage tutorial * add more info about mat.data * Change Size to value_object * Integrate Moh and Sajjad's editing into introduction page * Change Point to value_object * Change Rect to value_object with helper object * Add helper objects for Point and Size * Change RotatedRect to value_object with helpers * Change MinMaxLoc and Circle to value_object * Change TermCriteria to value_object * Fix core_bindings.cpp for MinMaxLoc and Circle * Remove unused types * Change meanShift and CamShift to return Rect * Change methods of RotatedRect to static * Change mat.data from methods to property Fix #75 and #77 * support img id and element in cv.imread * Change mat.size to property and add mat.step Fix #163 * Add matFromArray and matFromImageData as JS helpers Fix #79, #78 * Lower camel case for Mat element getters Fix #81 * Mat.getRoiRect and tests Fix #86 * Support type for Mat.ptr Fix #83 * Name changing of Mat element getters 'getUcharAt` -> 'ucharAt' * fix code style and args names * Fix helpers.js due to cv.Mat API update * Fix opencv.js usage tutorial * Fix a typo of js_setup * Change Moments to value_object * Add Range as value_object Fix #171 * Support Mat.diag and Mat.isContinous Fix #84 and #89 * Support Mat.setTo Fix #88 * Apply edits to js_intro * Apply edits to js_usage * Apply edits to js_setup * update tutorials to apply data type change * Modify tutorials * add core tutorials * delete MatVector elements and delete useless set operation * add tutorials_objdec_camera * Add instructions for WebAssembly * apply tech writer's feedbacks into tutorials * Organize white list by modules * Change size to method and bind to MatExpr.size() Fix #177 * improve tutorials * Modify core tutorials * add params list and explanations for OpenCV.js functions * remove face_profile from Face Detection in Video Capture * Add demos link * Change Gui to GUI * Update js_intro based on Moh and Sajjad's edits * Fixup for 3.3.0 rebase * Update js_intro per Moh's suggestion * Update contributors list per Moh's idea * add adapter.js in video_display tutorial * Change Mat.getRoiRect to Mat.roi Fix #194 * Remove unnecessary files for test Fix #192 * Licenses updated to UC BSD 3-Clause * Apply OpenCV coding style for C++ files * Add OpenCV license for python and js files * Fix coding style issue in helpers.js * Remove unused test_commons.js * Fix coding style of test_imgproc.js * Fix coding style of test_mat.js * Fix space before semicolon * Fix coding style of test_objdetect.js * Fix coding style of tests.js * Fix coding style of test_utils.js * Fix coding style of test_video.js * Fix failures of node.js tests * Add eslint rule config and fix eslint errors * Add eslint config for js/src and fix eslint errors * Clean up the opencv.js dependencies Fix #186 * Fix build issue for python generator * Fix doxygen buildbot failure * delete trailing whitespace, blank line at EOF and replace tab with space * Fix tutorial_js_root reference issue for non opencv.js build * replace the file with small size * Initial commit of build_js.py * Move the js build configurations to build script * Add wasm build support * Update OpenCV.js build tutorial by using script * Fix global var issue in tests * Add a README.md for build_js.py * Copy the haar cascade files from data dir for tutorials * Not use memory init file * Disable debug print for modules/js/CMakeLists.txt * Check files when build done * Fix image name in js_gradients tutorial * Fix image load issue in js_trackbar tutorial * Find the opencv source directory via relative path by default * Make the cmake args based on build_doc option * Fix a typo in js_setup.markdown * Fix make failure issue on config generated by build_js.py * Eliminate js branch of hdr_parser.py * Extract examples from js_basic_ops tutorial * Fix coding style of utils.js * Improve examples error handling Handle: 1. opencv.js loading errors 2. script errors (Error) 3. cv::Exception Fix #217 * Add enable_exception option into build_js.py * Support print exception for exception catching disabled build * Extract example from js_usage tutorial * Avoid copying .eslintrc.json when building doc Fix #223 * Revert to use onload as opencv.js ready event * Use 4 spaces indention for js examples * embed html in tutorials with iframe tag * Revert to use onload as opencv.js ready event * Extract examples from js_video_display tutorial * Implement Utils object * modify core imgprc and face_detection tutorials * Fix examples of js_gui tutorials * Fix coding style of utils.js * Modify tutorials * Extract example from js_face_detection_camera tutorial * Disable new-cap check in eslint * Extract examples from js_meanshift tutorial * Extract examples from video tutorials * Remove new-cap declaration and update grammer in comments * Change textarea width to 100 to align with eslint config * Fix printError issue when opencv.js loading fails * Remove BUILD_opencv_js dependency for doc build Fix #213 * Expose cv::getBuildInformation * Dump opencv build info when opencv.js loaded for live examples * Make the button to stand out in js live examples Fix #235 * Style for disabled button * Add js_imgproc_camera.html example * Fix coding style of imgproc_camera example * Add js_imgproc_camera tutorial * Remove link to opencv.js demos * doc: copy opencv.js on build, use absolute paths for assets * doc: reuse existed file box.mp4
2017-09-25 21:52:07 +08:00
elif retcode > 0:
raise Fail("Child returned: %s" % retcode)
except OSError as e:
raise Fail("Execution failed: %d / %s" % (e.errno, e.strerror))
def rm_one(d):
d = os.path.abspath(d)
if os.path.exists(d):
if os.path.isdir(d):
log.info("Removing dir: %s", d)
shutil.rmtree(d)
elif os.path.isfile(d):
log.info("Removing file: %s", d)
os.remove(d)
def check_dir(d, create=False, clean=False):
d = os.path.abspath(d)
log.info("Check dir %s (create: %s, clean: %s)", d, create, clean)
if os.path.exists(d):
if not os.path.isdir(d):
raise Fail("Not a directory: %s" % d)
if clean:
for x in glob.glob(os.path.join(d, "*")):
rm_one(x)
else:
if create:
os.makedirs(d)
return d
def check_file(d):
d = os.path.abspath(d)
if os.path.exists(d):
if os.path.isfile(d):
return True
else:
return False
return False
def find_file(name, path):
for root, dirs, files in os.walk(path):
if name in files:
return os.path.join(root, name)
def determine_emcc_version(emscripten_dir):
ret = subprocess.check_output([os.path.join(emscripten_dir, "emcc"), "--version"])
m = re.match(r'^emcc.*(\d+\.\d+\.\d+)', ret, flags=re.IGNORECASE)
return m.group(1)
def determine_opencv_version(version_hpp_path):
# version in 2.4 - CV_VERSION_EPOCH.CV_VERSION_MAJOR.CV_VERSION_MINOR.CV_VERSION_REVISION
# version in master - CV_VERSION_MAJOR.CV_VERSION_MINOR.CV_VERSION_REVISION-CV_VERSION_STATUS
with open(version_hpp_path, "rt") as f:
data = f.read()
major = re.search(r'^#define\W+CV_VERSION_MAJOR\W+(\d+)$', data, re.MULTILINE).group(1)
minor = re.search(r'^#define\W+CV_VERSION_MINOR\W+(\d+)$', data, re.MULTILINE).group(1)
revision = re.search(r'^#define\W+CV_VERSION_REVISION\W+(\d+)$', data, re.MULTILINE).group(1)
version_status = re.search(r'^#define\W+CV_VERSION_STATUS\W+"([^"]*)"$', data, re.MULTILINE).group(1)
return "%(major)s.%(minor)s.%(revision)s%(version_status)s" % locals()
class Builder:
def __init__(self, options):
self.options = options
self.build_dir = check_dir(options.build_dir, create=True)
self.opencv_dir = check_dir(options.opencv_dir)
self.emscripten_dir = check_dir(options.emscripten_dir)
self.opencv_version = determine_opencv_version(os.path.join(self.opencv_dir, "modules", "core", "include", "opencv2", "core", "version.hpp"))
self.emcc_version = determine_emcc_version(self.emscripten_dir)
def get_toolchain_file(self):
return os.path.join(self.emscripten_dir, "cmake", "Modules", "Platform", "Emscripten.cmake")
def clean_build_dir(self):
for d in ["CMakeCache.txt", "CMakeFiles/", "bin/", "libs/", "lib/", "modules"]:
rm_one(d)
def get_cmake_cmd(self):
cmd = ["cmake",
"-DCMAKE_BUILD_TYPE=Release",
"-DCMAKE_TOOLCHAIN_FILE='%s'" % self.get_toolchain_file(),
"-DCPU_BASELINE=''",
"-DCPU_DISPATCH=''",
"-DCV_TRACE=OFF",
"-DBUILD_SHARED_LIBS=OFF",
"-DWITH_1394=OFF",
"-DWITH_VTK=OFF",
"-DWITH_EIGEN=OFF",
"-DWITH_FFMPEG=OFF",
"-DWITH_GSTREAMER=OFF",
"-DWITH_GTK=OFF",
"-DWITH_GTK_2_X=OFF",
"-DWITH_IPP=OFF",
"-DWITH_JASPER=OFF",
"-DWITH_JPEG=OFF",
"-DWITH_WEBP=OFF",
"-DWITH_OPENEXR=OFF",
"-DWITH_OPENGL=OFF",
"-DWITH_OPENVX=OFF",
"-DWITH_OPENNI=OFF",
"-DWITH_OPENNI2=OFF",
"-DWITH_PNG=OFF",
"-DWITH_TBB=OFF",
"-DWITH_PTHREADS_PF=OFF",
"-DWITH_TIFF=OFF",
"-DWITH_V4L=OFF",
"-DWITH_OPENCL=OFF",
"-DWITH_OPENCL_SVM=OFF",
"-DWITH_OPENCLAMDFFT=OFF",
"-DWITH_OPENCLAMDBLAS=OFF",
"-DWITH_MATLAB=OFF",
"-DWITH_GPHOTO2=OFF",
"-DWITH_LAPACK=OFF",
"-DWITH_ITT=OFF",
"-DBUILD_ZLIB=ON",
"-DBUILD_opencv_apps=OFF",
"-DBUILD_opencv_calib3d=ON",
2017-12-03 04:52:35 +08:00
"-DBUILD_opencv_dnn=ON",
Merge pull request #9466 from huningxin:js GSoC 2017: Improve and Extend the JavaScript Bindings for OpenCV (#9466) * Initial support for build with emscripten mkdir build_js cd build_js cmake -D CMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emsdk-portable/emscripten/master/cmake/Modules/Platform/Emscripten.cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. * Add js module The output is build/bin/opencv_js.js * Fix opencv2/calib3d.hpp not found issue * Add module name Usage: var cv = cv(); * Add total memory as 128MB and allow growth * Add compilation flags for emscripten * Use EMSCRIPTEN build target * Disable js module for non emscripten build * Bind the preload file path to root Usage: face_cascade.load('haarcascade_frontalface_default.xml'); * add test folder * fix test files * Copy js module test to bin * Support to run tests on Node.js Fix tests to import cv Module when runtime is node. Add tests.js to use qunit to auto run tests. Modify umd wrapper to support Module is not defined. Usage: node tests.js * Support UMD and file system Wrap the opencv_js.js to opencv.js by UMD wrapper Use emscripten file system API to load files instead of generating data file or embedding them. It supports both browser and node.js usages. * Fix incorrect module name in tests * Add package.json to add dependence of qunit * Add js_tutorials folder and a intro page of opencv.js Enable BUILD_DOCS in CMakeLists.txt. Add new folder of js_tutorials in folder opencv/doc. Imitate the tutorials of OpenCV-Python to create a intro page of opencv.js and a setup guide * Import and use binding gen from opencvjs project * Modify the embindgen.py to pass the build and test * Add classes and functions white list * Consolidate hdr_parser.py (#31) Use hdr_parser.py of python module Add js flag to support js binding generator. * Use emscripten::vecFromJSArray for input vector param Fix part of #23 * Fix test cases after #34 Fix #39 * Expose groupRectangles and CascadeClassifier.empty * Add js highgui tutorials add tutorials of imread&imshow and createTrackbar in doc/js_tutorials/js_gui folder add interactive tutorial webpage for imread&imshow and createTrackbar in doc/js_tutorials/js_interactive_tutorials folder, and some images needed. change doc/CMakeLists.txt to copy the interactive tutorial webpage and opencv.js to the tutorials' destination folder * rm useless annotation in doc/CMakeLists.txt * fix some nonstandard indentation and space * add check if canvas is valid * Expose BackgroundSubtractorMOG2 Fix #43 * Fix build of js doc Limit copy_js_interactive_tutorials for doxygen build Add dep to opencv.js Fix #53 * Implement cv.imread & cv.imshow and insert interactive pages in tutorials (#55) * add helper.js * delete ALL in add target copy_js_interactive_tutorials to avoid dependence error * Insert interactive pages in tutorials insert the old interactive pages in markdown by using \htmlonly and \endhtmlonly command. delete the useless interactive page rename js_interactive_tutorials to js_assets to put some images needed in * fix the depends of the target doxygen add opencv.js to depends and delete the useless target of copy_js_assets * change filename helper.js to helpers.js * disable button or trankbar before opencv.js is ready * Expose CV_64F Fix #65 * improve cv.imshow to display different types as native imshow * add utils.js to reuse functions and update tutorials * Make doxygen depend on bin/opencv.js * Fix memory issue of matFromArray Fix #37 * Merge pull request from ganwenyao/tutorial_18 * Add notes for ganwenyao/tutorial_18 * Modifying for ganwenyao/tutorial_18 * Change Mat constructor with data to 5 parameters * Mat supports constructor with Scalar Fix #60 * update cv.imread cause the memory issue of matFromArray has been fixed * fix canvas name and default input image * Expose cv::Moments Fix #85 * Add -Wno-missing-prototypes for emscripten build * fix canvas name * add tutorial of video input and output * Expose enums as emscripten consts Fix #72 * update the tutorial to use Mat constructor with Scalar and change lena.jpg * Exclude cv::Mat for vecFromJSArray Fix #82 * Add unit tests for cv.moments * Fix the unit tests. * add checkbox and stop button * add adapter.js to make sure compatibility fo video tutorials * Support default parameters with function overloading * modify enums to constants * Use https URL for MathJax.js Fix #109 * Comment out the debug print in embindgen.py * Expose RotatedRect Fix #96 * replace enum with constants and improve onload function * delete some useless paras cause #105 fixed this * Modify const name * Modify Contour Properties * tutorials for imgprc2 and objdec * Expose more functions for img proc tutorials Fix #76 * Expose polylines for video analysis tutorial Fix #121 * Expose constants for default parameters of img proc tutorials Fix #122 * Fix wrong parameter types of Mat.copyTo Fix #87 * Support default parameters of mat.convertTo Fix #123 * Support default parameters for external constructors Fix #131 * Revert "Expose polylines for video analysis tutorial" This reverts commit 3ce7615652e510d30e3c0014706ac38c98883189. Fix #121 * Support cv.minMaxLoc Fix #127 * Expose cv.minEnclosingCircle Fix #126 * Add video analysis tutorials add three video tutorials, Meanshift and Camshift, Optical Flow Background Subtraction add cup.mp4 and box.mp4 for demo in tutorials * improve image processing tutorials * repalce console.warn with throw to throw exception * add try-catch to throw exception in code demo * Change mat.size() return value to JS Array object Fix #140 * add a note about different channels order between canvas and native opencv * add a note about how to capture video from video files * Binding cv.Scalar to JS array Fix #147 * Add JS cv.Scalar object into helpers.js * Update Install OpenCV-JavaScript tutorial page Fix #44 * Update the OpenCV-JavaScript introduction page Fix #44 * add cv.VideoCapture and read() function * set the size of the hidden canvas same as the video * Add Using OpenCV-JavaScript tutorial page Fix #44 * fix some bad code style * Update tutorials after 8/2 sync meeting Changes include: - Use OpenCV.js name instead of OpenCV-JavaScript - Put using OpenCV.js ahead of build OpenCV.js - Refine usage and introduction page - Muted the video in tutorials * Fix a typo in introduction page * use cv.VideoCapture and its read() function to read video * replace OpenCV-JavaScript with OpenCV.js * Use onload of async script in js_usage tutorial * add more info about mat.data * Change Size to value_object * Integrate Moh and Sajjad's editing into introduction page * Change Point to value_object * Change Rect to value_object with helper object * Add helper objects for Point and Size * Change RotatedRect to value_object with helpers * Change MinMaxLoc and Circle to value_object * Change TermCriteria to value_object * Fix core_bindings.cpp for MinMaxLoc and Circle * Remove unused types * Change meanShift and CamShift to return Rect * Change methods of RotatedRect to static * Change mat.data from methods to property Fix #75 and #77 * support img id and element in cv.imread * Change mat.size to property and add mat.step Fix #163 * Add matFromArray and matFromImageData as JS helpers Fix #79, #78 * Lower camel case for Mat element getters Fix #81 * Mat.getRoiRect and tests Fix #86 * Support type for Mat.ptr Fix #83 * Name changing of Mat element getters 'getUcharAt` -> 'ucharAt' * fix code style and args names * Fix helpers.js due to cv.Mat API update * Fix opencv.js usage tutorial * Fix a typo of js_setup * Change Moments to value_object * Add Range as value_object Fix #171 * Support Mat.diag and Mat.isContinous Fix #84 and #89 * Support Mat.setTo Fix #88 * Apply edits to js_intro * Apply edits to js_usage * Apply edits to js_setup * update tutorials to apply data type change * Modify tutorials * add core tutorials * delete MatVector elements and delete useless set operation * add tutorials_objdec_camera * Add instructions for WebAssembly * apply tech writer's feedbacks into tutorials * Organize white list by modules * Change size to method and bind to MatExpr.size() Fix #177 * improve tutorials * Modify core tutorials * add params list and explanations for OpenCV.js functions * remove face_profile from Face Detection in Video Capture * Add demos link * Change Gui to GUI * Update js_intro based on Moh and Sajjad's edits * Fixup for 3.3.0 rebase * Update js_intro per Moh's suggestion * Update contributors list per Moh's idea * add adapter.js in video_display tutorial * Change Mat.getRoiRect to Mat.roi Fix #194 * Remove unnecessary files for test Fix #192 * Licenses updated to UC BSD 3-Clause * Apply OpenCV coding style for C++ files * Add OpenCV license for python and js files * Fix coding style issue in helpers.js * Remove unused test_commons.js * Fix coding style of test_imgproc.js * Fix coding style of test_mat.js * Fix space before semicolon * Fix coding style of test_objdetect.js * Fix coding style of tests.js * Fix coding style of test_utils.js * Fix coding style of test_video.js * Fix failures of node.js tests * Add eslint rule config and fix eslint errors * Add eslint config for js/src and fix eslint errors * Clean up the opencv.js dependencies Fix #186 * Fix build issue for python generator * Fix doxygen buildbot failure * delete trailing whitespace, blank line at EOF and replace tab with space * Fix tutorial_js_root reference issue for non opencv.js build * replace the file with small size * Initial commit of build_js.py * Move the js build configurations to build script * Add wasm build support * Update OpenCV.js build tutorial by using script * Fix global var issue in tests * Add a README.md for build_js.py * Copy the haar cascade files from data dir for tutorials * Not use memory init file * Disable debug print for modules/js/CMakeLists.txt * Check files when build done * Fix image name in js_gradients tutorial * Fix image load issue in js_trackbar tutorial * Find the opencv source directory via relative path by default * Make the cmake args based on build_doc option * Fix a typo in js_setup.markdown * Fix make failure issue on config generated by build_js.py * Eliminate js branch of hdr_parser.py * Extract examples from js_basic_ops tutorial * Fix coding style of utils.js * Improve examples error handling Handle: 1. opencv.js loading errors 2. script errors (Error) 3. cv::Exception Fix #217 * Add enable_exception option into build_js.py * Support print exception for exception catching disabled build * Extract example from js_usage tutorial * Avoid copying .eslintrc.json when building doc Fix #223 * Revert to use onload as opencv.js ready event * Use 4 spaces indention for js examples * embed html in tutorials with iframe tag * Revert to use onload as opencv.js ready event * Extract examples from js_video_display tutorial * Implement Utils object * modify core imgprc and face_detection tutorials * Fix examples of js_gui tutorials * Fix coding style of utils.js * Modify tutorials * Extract example from js_face_detection_camera tutorial * Disable new-cap check in eslint * Extract examples from js_meanshift tutorial * Extract examples from video tutorials * Remove new-cap declaration and update grammer in comments * Change textarea width to 100 to align with eslint config * Fix printError issue when opencv.js loading fails * Remove BUILD_opencv_js dependency for doc build Fix #213 * Expose cv::getBuildInformation * Dump opencv build info when opencv.js loaded for live examples * Make the button to stand out in js live examples Fix #235 * Style for disabled button * Add js_imgproc_camera.html example * Fix coding style of imgproc_camera example * Add js_imgproc_camera tutorial * Remove link to opencv.js demos * doc: copy opencv.js on build, use absolute paths for assets * doc: reuse existed file box.mp4
2017-09-25 21:52:07 +08:00
"-DBUILD_opencv_features2d=OFF",
"-DBUILD_opencv_flann=OFF",
"-DBUILD_opencv_ml=OFF",
"-DBUILD_opencv_photo=OFF",
"-DBUILD_opencv_imgcodecs=OFF",
"-DBUILD_opencv_shape=OFF",
"-DBUILD_opencv_videoio=OFF",
"-DBUILD_opencv_videostab=OFF",
"-DBUILD_opencv_highgui=OFF",
"-DBUILD_opencv_superres=OFF",
"-DBUILD_opencv_stitching=OFF",
"-DBUILD_opencv_java=OFF",
"-DBUILD_opencv_js=ON",
"-DBUILD_opencv_python2=OFF",
"-DBUILD_opencv_python3=OFF",
"-DBUILD_EXAMPLES=OFF",
"-DBUILD_PACKAGE=OFF",
"-DBUILD_TESTS=OFF",
"-DBUILD_PERF_TESTS=OFF"]
if self.options.build_doc:
cmd.append("-DBUILD_DOCS=ON")
else:
cmd.append("-DBUILD_DOCS=OFF")
flags = self.get_build_flags()
if flags:
cmd += ["-DCMAKE_C_FLAGS='%s'" % flags,
"-DCMAKE_CXX_FLAGS='%s'" % flags]
2018-05-03 13:47:34 +08:00
return cmd
Merge pull request #9466 from huningxin:js GSoC 2017: Improve and Extend the JavaScript Bindings for OpenCV (#9466) * Initial support for build with emscripten mkdir build_js cd build_js cmake -D CMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emsdk-portable/emscripten/master/cmake/Modules/Platform/Emscripten.cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. * Add js module The output is build/bin/opencv_js.js * Fix opencv2/calib3d.hpp not found issue * Add module name Usage: var cv = cv(); * Add total memory as 128MB and allow growth * Add compilation flags for emscripten * Use EMSCRIPTEN build target * Disable js module for non emscripten build * Bind the preload file path to root Usage: face_cascade.load('haarcascade_frontalface_default.xml'); * add test folder * fix test files * Copy js module test to bin * Support to run tests on Node.js Fix tests to import cv Module when runtime is node. Add tests.js to use qunit to auto run tests. Modify umd wrapper to support Module is not defined. Usage: node tests.js * Support UMD and file system Wrap the opencv_js.js to opencv.js by UMD wrapper Use emscripten file system API to load files instead of generating data file or embedding them. It supports both browser and node.js usages. * Fix incorrect module name in tests * Add package.json to add dependence of qunit * Add js_tutorials folder and a intro page of opencv.js Enable BUILD_DOCS in CMakeLists.txt. Add new folder of js_tutorials in folder opencv/doc. Imitate the tutorials of OpenCV-Python to create a intro page of opencv.js and a setup guide * Import and use binding gen from opencvjs project * Modify the embindgen.py to pass the build and test * Add classes and functions white list * Consolidate hdr_parser.py (#31) Use hdr_parser.py of python module Add js flag to support js binding generator. * Use emscripten::vecFromJSArray for input vector param Fix part of #23 * Fix test cases after #34 Fix #39 * Expose groupRectangles and CascadeClassifier.empty * Add js highgui tutorials add tutorials of imread&imshow and createTrackbar in doc/js_tutorials/js_gui folder add interactive tutorial webpage for imread&imshow and createTrackbar in doc/js_tutorials/js_interactive_tutorials folder, and some images needed. change doc/CMakeLists.txt to copy the interactive tutorial webpage and opencv.js to the tutorials' destination folder * rm useless annotation in doc/CMakeLists.txt * fix some nonstandard indentation and space * add check if canvas is valid * Expose BackgroundSubtractorMOG2 Fix #43 * Fix build of js doc Limit copy_js_interactive_tutorials for doxygen build Add dep to opencv.js Fix #53 * Implement cv.imread & cv.imshow and insert interactive pages in tutorials (#55) * add helper.js * delete ALL in add target copy_js_interactive_tutorials to avoid dependence error * Insert interactive pages in tutorials insert the old interactive pages in markdown by using \htmlonly and \endhtmlonly command. delete the useless interactive page rename js_interactive_tutorials to js_assets to put some images needed in * fix the depends of the target doxygen add opencv.js to depends and delete the useless target of copy_js_assets * change filename helper.js to helpers.js * disable button or trankbar before opencv.js is ready * Expose CV_64F Fix #65 * improve cv.imshow to display different types as native imshow * add utils.js to reuse functions and update tutorials * Make doxygen depend on bin/opencv.js * Fix memory issue of matFromArray Fix #37 * Merge pull request from ganwenyao/tutorial_18 * Add notes for ganwenyao/tutorial_18 * Modifying for ganwenyao/tutorial_18 * Change Mat constructor with data to 5 parameters * Mat supports constructor with Scalar Fix #60 * update cv.imread cause the memory issue of matFromArray has been fixed * fix canvas name and default input image * Expose cv::Moments Fix #85 * Add -Wno-missing-prototypes for emscripten build * fix canvas name * add tutorial of video input and output * Expose enums as emscripten consts Fix #72 * update the tutorial to use Mat constructor with Scalar and change lena.jpg * Exclude cv::Mat for vecFromJSArray Fix #82 * Add unit tests for cv.moments * Fix the unit tests. * add checkbox and stop button * add adapter.js to make sure compatibility fo video tutorials * Support default parameters with function overloading * modify enums to constants * Use https URL for MathJax.js Fix #109 * Comment out the debug print in embindgen.py * Expose RotatedRect Fix #96 * replace enum with constants and improve onload function * delete some useless paras cause #105 fixed this * Modify const name * Modify Contour Properties * tutorials for imgprc2 and objdec * Expose more functions for img proc tutorials Fix #76 * Expose polylines for video analysis tutorial Fix #121 * Expose constants for default parameters of img proc tutorials Fix #122 * Fix wrong parameter types of Mat.copyTo Fix #87 * Support default parameters of mat.convertTo Fix #123 * Support default parameters for external constructors Fix #131 * Revert "Expose polylines for video analysis tutorial" This reverts commit 3ce7615652e510d30e3c0014706ac38c98883189. Fix #121 * Support cv.minMaxLoc Fix #127 * Expose cv.minEnclosingCircle Fix #126 * Add video analysis tutorials add three video tutorials, Meanshift and Camshift, Optical Flow Background Subtraction add cup.mp4 and box.mp4 for demo in tutorials * improve image processing tutorials * repalce console.warn with throw to throw exception * add try-catch to throw exception in code demo * Change mat.size() return value to JS Array object Fix #140 * add a note about different channels order between canvas and native opencv * add a note about how to capture video from video files * Binding cv.Scalar to JS array Fix #147 * Add JS cv.Scalar object into helpers.js * Update Install OpenCV-JavaScript tutorial page Fix #44 * Update the OpenCV-JavaScript introduction page Fix #44 * add cv.VideoCapture and read() function * set the size of the hidden canvas same as the video * Add Using OpenCV-JavaScript tutorial page Fix #44 * fix some bad code style * Update tutorials after 8/2 sync meeting Changes include: - Use OpenCV.js name instead of OpenCV-JavaScript - Put using OpenCV.js ahead of build OpenCV.js - Refine usage and introduction page - Muted the video in tutorials * Fix a typo in introduction page * use cv.VideoCapture and its read() function to read video * replace OpenCV-JavaScript with OpenCV.js * Use onload of async script in js_usage tutorial * add more info about mat.data * Change Size to value_object * Integrate Moh and Sajjad's editing into introduction page * Change Point to value_object * Change Rect to value_object with helper object * Add helper objects for Point and Size * Change RotatedRect to value_object with helpers * Change MinMaxLoc and Circle to value_object * Change TermCriteria to value_object * Fix core_bindings.cpp for MinMaxLoc and Circle * Remove unused types * Change meanShift and CamShift to return Rect * Change methods of RotatedRect to static * Change mat.data from methods to property Fix #75 and #77 * support img id and element in cv.imread * Change mat.size to property and add mat.step Fix #163 * Add matFromArray and matFromImageData as JS helpers Fix #79, #78 * Lower camel case for Mat element getters Fix #81 * Mat.getRoiRect and tests Fix #86 * Support type for Mat.ptr Fix #83 * Name changing of Mat element getters 'getUcharAt` -> 'ucharAt' * fix code style and args names * Fix helpers.js due to cv.Mat API update * Fix opencv.js usage tutorial * Fix a typo of js_setup * Change Moments to value_object * Add Range as value_object Fix #171 * Support Mat.diag and Mat.isContinous Fix #84 and #89 * Support Mat.setTo Fix #88 * Apply edits to js_intro * Apply edits to js_usage * Apply edits to js_setup * update tutorials to apply data type change * Modify tutorials * add core tutorials * delete MatVector elements and delete useless set operation * add tutorials_objdec_camera * Add instructions for WebAssembly * apply tech writer's feedbacks into tutorials * Organize white list by modules * Change size to method and bind to MatExpr.size() Fix #177 * improve tutorials * Modify core tutorials * add params list and explanations for OpenCV.js functions * remove face_profile from Face Detection in Video Capture * Add demos link * Change Gui to GUI * Update js_intro based on Moh and Sajjad's edits * Fixup for 3.3.0 rebase * Update js_intro per Moh's suggestion * Update contributors list per Moh's idea * add adapter.js in video_display tutorial * Change Mat.getRoiRect to Mat.roi Fix #194 * Remove unnecessary files for test Fix #192 * Licenses updated to UC BSD 3-Clause * Apply OpenCV coding style for C++ files * Add OpenCV license for python and js files * Fix coding style issue in helpers.js * Remove unused test_commons.js * Fix coding style of test_imgproc.js * Fix coding style of test_mat.js * Fix space before semicolon * Fix coding style of test_objdetect.js * Fix coding style of tests.js * Fix coding style of test_utils.js * Fix coding style of test_video.js * Fix failures of node.js tests * Add eslint rule config and fix eslint errors * Add eslint config for js/src and fix eslint errors * Clean up the opencv.js dependencies Fix #186 * Fix build issue for python generator * Fix doxygen buildbot failure * delete trailing whitespace, blank line at EOF and replace tab with space * Fix tutorial_js_root reference issue for non opencv.js build * replace the file with small size * Initial commit of build_js.py * Move the js build configurations to build script * Add wasm build support * Update OpenCV.js build tutorial by using script * Fix global var issue in tests * Add a README.md for build_js.py * Copy the haar cascade files from data dir for tutorials * Not use memory init file * Disable debug print for modules/js/CMakeLists.txt * Check files when build done * Fix image name in js_gradients tutorial * Fix image load issue in js_trackbar tutorial * Find the opencv source directory via relative path by default * Make the cmake args based on build_doc option * Fix a typo in js_setup.markdown * Fix make failure issue on config generated by build_js.py * Eliminate js branch of hdr_parser.py * Extract examples from js_basic_ops tutorial * Fix coding style of utils.js * Improve examples error handling Handle: 1. opencv.js loading errors 2. script errors (Error) 3. cv::Exception Fix #217 * Add enable_exception option into build_js.py * Support print exception for exception catching disabled build * Extract example from js_usage tutorial * Avoid copying .eslintrc.json when building doc Fix #223 * Revert to use onload as opencv.js ready event * Use 4 spaces indention for js examples * embed html in tutorials with iframe tag * Revert to use onload as opencv.js ready event * Extract examples from js_video_display tutorial * Implement Utils object * modify core imgprc and face_detection tutorials * Fix examples of js_gui tutorials * Fix coding style of utils.js * Modify tutorials * Extract example from js_face_detection_camera tutorial * Disable new-cap check in eslint * Extract examples from js_meanshift tutorial * Extract examples from video tutorials * Remove new-cap declaration and update grammer in comments * Change textarea width to 100 to align with eslint config * Fix printError issue when opencv.js loading fails * Remove BUILD_opencv_js dependency for doc build Fix #213 * Expose cv::getBuildInformation * Dump opencv build info when opencv.js loaded for live examples * Make the button to stand out in js live examples Fix #235 * Style for disabled button * Add js_imgproc_camera.html example * Fix coding style of imgproc_camera example * Add js_imgproc_camera tutorial * Remove link to opencv.js demos * doc: copy opencv.js on build, use absolute paths for assets * doc: reuse existed file box.mp4
2017-09-25 21:52:07 +08:00
def get_build_flags(self):
flags = ""
if self.options.build_wasm:
flags += "-s WASM=1 "
if self.options.enable_exception:
flags += "-s DISABLE_EXCEPTION_CATCHING=0 "
return flags
def config(self):
cmd = self.get_cmake_cmd()
cmd.append(self.opencv_dir)
execute(cmd)
def build_opencvjs(self):
execute(["make", "-j", str(multiprocessing.cpu_count()), "opencv.js"])
def build_test(self):
execute(["make", "-j", str(multiprocessing.cpu_count()), "opencv_js_test"])
def build_doc(self):
execute(["make", "-j", str(multiprocessing.cpu_count()), "doxygen"])
#===================================================================================================
if __name__ == "__main__":
opencv_dir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), "../.."))
emscripten_dir = None
if "EMSCRIPTEN" in os.environ:
emscripten_dir = os.environ["EMSCRIPTEN"]
parser = argparse.ArgumentParser(description='Build OpenCV.js by Emscripten')
parser.add_argument("build_dir", help="Building directory (and output)")
parser.add_argument('--opencv_dir', default=opencv_dir, help='Opencv source directory (default is "../.." relative to script location)')
parser.add_argument('--emscripten_dir', default=emscripten_dir, help="Path to Emscripten to use for build")
parser.add_argument('--build_wasm', action="store_true", help="Build OpenCV.js in WebAssembly format")
parser.add_argument('--build_test', action="store_true", help="Build tests")
parser.add_argument('--build_doc', action="store_true", help="Build tutorials")
parser.add_argument('--clean_build_dir', action="store_true", help="Clean build dir")
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")
args = parser.parse_args()
log.basicConfig(format='%(message)s', level=log.DEBUG)
log.debug("Args: %s", args)
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)
builder = Builder(args)
log.info("Detected OpenCV version: %s", builder.opencv_version)
log.info("Detected emcc version: %s", builder.emcc_version)
os.chdir(builder.build_dir)
if args.clean_build_dir:
log.info("=====")
log.info("===== Clean build dir %s", builder.build_dir)
log.info("=====")
builder.clean_build_dir()
if not args.skip_config:
target = "asm.js"
if args.build_wasm:
target = "wasm"
log.info("=====")
log.info("===== Config OpenCV.js build for %s" % target)
log.info("=====")
builder.config()
if args.config_only:
2018-05-03 13:47:34 +08:00
sys.exit(0)
Merge pull request #9466 from huningxin:js GSoC 2017: Improve and Extend the JavaScript Bindings for OpenCV (#9466) * Initial support for build with emscripten mkdir build_js cd build_js cmake -D CMAKE_TOOLCHAIN_FILE=/path/to/emsdk/emsdk-portable/emscripten/master/cmake/Modules/Platform/Emscripten.cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local .. * Add js module The output is build/bin/opencv_js.js * Fix opencv2/calib3d.hpp not found issue * Add module name Usage: var cv = cv(); * Add total memory as 128MB and allow growth * Add compilation flags for emscripten * Use EMSCRIPTEN build target * Disable js module for non emscripten build * Bind the preload file path to root Usage: face_cascade.load('haarcascade_frontalface_default.xml'); * add test folder * fix test files * Copy js module test to bin * Support to run tests on Node.js Fix tests to import cv Module when runtime is node. Add tests.js to use qunit to auto run tests. Modify umd wrapper to support Module is not defined. Usage: node tests.js * Support UMD and file system Wrap the opencv_js.js to opencv.js by UMD wrapper Use emscripten file system API to load files instead of generating data file or embedding them. It supports both browser and node.js usages. * Fix incorrect module name in tests * Add package.json to add dependence of qunit * Add js_tutorials folder and a intro page of opencv.js Enable BUILD_DOCS in CMakeLists.txt. Add new folder of js_tutorials in folder opencv/doc. Imitate the tutorials of OpenCV-Python to create a intro page of opencv.js and a setup guide * Import and use binding gen from opencvjs project * Modify the embindgen.py to pass the build and test * Add classes and functions white list * Consolidate hdr_parser.py (#31) Use hdr_parser.py of python module Add js flag to support js binding generator. * Use emscripten::vecFromJSArray for input vector param Fix part of #23 * Fix test cases after #34 Fix #39 * Expose groupRectangles and CascadeClassifier.empty * Add js highgui tutorials add tutorials of imread&imshow and createTrackbar in doc/js_tutorials/js_gui folder add interactive tutorial webpage for imread&imshow and createTrackbar in doc/js_tutorials/js_interactive_tutorials folder, and some images needed. change doc/CMakeLists.txt to copy the interactive tutorial webpage and opencv.js to the tutorials' destination folder * rm useless annotation in doc/CMakeLists.txt * fix some nonstandard indentation and space * add check if canvas is valid * Expose BackgroundSubtractorMOG2 Fix #43 * Fix build of js doc Limit copy_js_interactive_tutorials for doxygen build Add dep to opencv.js Fix #53 * Implement cv.imread & cv.imshow and insert interactive pages in tutorials (#55) * add helper.js * delete ALL in add target copy_js_interactive_tutorials to avoid dependence error * Insert interactive pages in tutorials insert the old interactive pages in markdown by using \htmlonly and \endhtmlonly command. delete the useless interactive page rename js_interactive_tutorials to js_assets to put some images needed in * fix the depends of the target doxygen add opencv.js to depends and delete the useless target of copy_js_assets * change filename helper.js to helpers.js * disable button or trankbar before opencv.js is ready * Expose CV_64F Fix #65 * improve cv.imshow to display different types as native imshow * add utils.js to reuse functions and update tutorials * Make doxygen depend on bin/opencv.js * Fix memory issue of matFromArray Fix #37 * Merge pull request from ganwenyao/tutorial_18 * Add notes for ganwenyao/tutorial_18 * Modifying for ganwenyao/tutorial_18 * Change Mat constructor with data to 5 parameters * Mat supports constructor with Scalar Fix #60 * update cv.imread cause the memory issue of matFromArray has been fixed * fix canvas name and default input image * Expose cv::Moments Fix #85 * Add -Wno-missing-prototypes for emscripten build * fix canvas name * add tutorial of video input and output * Expose enums as emscripten consts Fix #72 * update the tutorial to use Mat constructor with Scalar and change lena.jpg * Exclude cv::Mat for vecFromJSArray Fix #82 * Add unit tests for cv.moments * Fix the unit tests. * add checkbox and stop button * add adapter.js to make sure compatibility fo video tutorials * Support default parameters with function overloading * modify enums to constants * Use https URL for MathJax.js Fix #109 * Comment out the debug print in embindgen.py * Expose RotatedRect Fix #96 * replace enum with constants and improve onload function * delete some useless paras cause #105 fixed this * Modify const name * Modify Contour Properties * tutorials for imgprc2 and objdec * Expose more functions for img proc tutorials Fix #76 * Expose polylines for video analysis tutorial Fix #121 * Expose constants for default parameters of img proc tutorials Fix #122 * Fix wrong parameter types of Mat.copyTo Fix #87 * Support default parameters of mat.convertTo Fix #123 * Support default parameters for external constructors Fix #131 * Revert "Expose polylines for video analysis tutorial" This reverts commit 3ce7615652e510d30e3c0014706ac38c98883189. Fix #121 * Support cv.minMaxLoc Fix #127 * Expose cv.minEnclosingCircle Fix #126 * Add video analysis tutorials add three video tutorials, Meanshift and Camshift, Optical Flow Background Subtraction add cup.mp4 and box.mp4 for demo in tutorials * improve image processing tutorials * repalce console.warn with throw to throw exception * add try-catch to throw exception in code demo * Change mat.size() return value to JS Array object Fix #140 * add a note about different channels order between canvas and native opencv * add a note about how to capture video from video files * Binding cv.Scalar to JS array Fix #147 * Add JS cv.Scalar object into helpers.js * Update Install OpenCV-JavaScript tutorial page Fix #44 * Update the OpenCV-JavaScript introduction page Fix #44 * add cv.VideoCapture and read() function * set the size of the hidden canvas same as the video * Add Using OpenCV-JavaScript tutorial page Fix #44 * fix some bad code style * Update tutorials after 8/2 sync meeting Changes include: - Use OpenCV.js name instead of OpenCV-JavaScript - Put using OpenCV.js ahead of build OpenCV.js - Refine usage and introduction page - Muted the video in tutorials * Fix a typo in introduction page * use cv.VideoCapture and its read() function to read video * replace OpenCV-JavaScript with OpenCV.js * Use onload of async script in js_usage tutorial * add more info about mat.data * Change Size to value_object * Integrate Moh and Sajjad's editing into introduction page * Change Point to value_object * Change Rect to value_object with helper object * Add helper objects for Point and Size * Change RotatedRect to value_object with helpers * Change MinMaxLoc and Circle to value_object * Change TermCriteria to value_object * Fix core_bindings.cpp for MinMaxLoc and Circle * Remove unused types * Change meanShift and CamShift to return Rect * Change methods of RotatedRect to static * Change mat.data from methods to property Fix #75 and #77 * support img id and element in cv.imread * Change mat.size to property and add mat.step Fix #163 * Add matFromArray and matFromImageData as JS helpers Fix #79, #78 * Lower camel case for Mat element getters Fix #81 * Mat.getRoiRect and tests Fix #86 * Support type for Mat.ptr Fix #83 * Name changing of Mat element getters 'getUcharAt` -> 'ucharAt' * fix code style and args names * Fix helpers.js due to cv.Mat API update * Fix opencv.js usage tutorial * Fix a typo of js_setup * Change Moments to value_object * Add Range as value_object Fix #171 * Support Mat.diag and Mat.isContinous Fix #84 and #89 * Support Mat.setTo Fix #88 * Apply edits to js_intro * Apply edits to js_usage * Apply edits to js_setup * update tutorials to apply data type change * Modify tutorials * add core tutorials * delete MatVector elements and delete useless set operation * add tutorials_objdec_camera * Add instructions for WebAssembly * apply tech writer's feedbacks into tutorials * Organize white list by modules * Change size to method and bind to MatExpr.size() Fix #177 * improve tutorials * Modify core tutorials * add params list and explanations for OpenCV.js functions * remove face_profile from Face Detection in Video Capture * Add demos link * Change Gui to GUI * Update js_intro based on Moh and Sajjad's edits * Fixup for 3.3.0 rebase * Update js_intro per Moh's suggestion * Update contributors list per Moh's idea * add adapter.js in video_display tutorial * Change Mat.getRoiRect to Mat.roi Fix #194 * Remove unnecessary files for test Fix #192 * Licenses updated to UC BSD 3-Clause * Apply OpenCV coding style for C++ files * Add OpenCV license for python and js files * Fix coding style issue in helpers.js * Remove unused test_commons.js * Fix coding style of test_imgproc.js * Fix coding style of test_mat.js * Fix space before semicolon * Fix coding style of test_objdetect.js * Fix coding style of tests.js * Fix coding style of test_utils.js * Fix coding style of test_video.js * Fix failures of node.js tests * Add eslint rule config and fix eslint errors * Add eslint config for js/src and fix eslint errors * Clean up the opencv.js dependencies Fix #186 * Fix build issue for python generator * Fix doxygen buildbot failure * delete trailing whitespace, blank line at EOF and replace tab with space * Fix tutorial_js_root reference issue for non opencv.js build * replace the file with small size * Initial commit of build_js.py * Move the js build configurations to build script * Add wasm build support * Update OpenCV.js build tutorial by using script * Fix global var issue in tests * Add a README.md for build_js.py * Copy the haar cascade files from data dir for tutorials * Not use memory init file * Disable debug print for modules/js/CMakeLists.txt * Check files when build done * Fix image name in js_gradients tutorial * Fix image load issue in js_trackbar tutorial * Find the opencv source directory via relative path by default * Make the cmake args based on build_doc option * Fix a typo in js_setup.markdown * Fix make failure issue on config generated by build_js.py * Eliminate js branch of hdr_parser.py * Extract examples from js_basic_ops tutorial * Fix coding style of utils.js * Improve examples error handling Handle: 1. opencv.js loading errors 2. script errors (Error) 3. cv::Exception Fix #217 * Add enable_exception option into build_js.py * Support print exception for exception catching disabled build * Extract example from js_usage tutorial * Avoid copying .eslintrc.json when building doc Fix #223 * Revert to use onload as opencv.js ready event * Use 4 spaces indention for js examples * embed html in tutorials with iframe tag * Revert to use onload as opencv.js ready event * Extract examples from js_video_display tutorial * Implement Utils object * modify core imgprc and face_detection tutorials * Fix examples of js_gui tutorials * Fix coding style of utils.js * Modify tutorials * Extract example from js_face_detection_camera tutorial * Disable new-cap check in eslint * Extract examples from js_meanshift tutorial * Extract examples from video tutorials * Remove new-cap declaration and update grammer in comments * Change textarea width to 100 to align with eslint config * Fix printError issue when opencv.js loading fails * Remove BUILD_opencv_js dependency for doc build Fix #213 * Expose cv::getBuildInformation * Dump opencv build info when opencv.js loaded for live examples * Make the button to stand out in js live examples Fix #235 * Style for disabled button * Add js_imgproc_camera.html example * Fix coding style of imgproc_camera example * Add js_imgproc_camera tutorial * Remove link to opencv.js demos * doc: copy opencv.js on build, use absolute paths for assets * doc: reuse existed file box.mp4
2017-09-25 21:52:07 +08:00
log.info("=====")
log.info("===== Building OpenCV.js in %s", "asm.js" if not args.build_wasm else "wasm")
log.info("=====")
builder.build_opencvjs()
if args.build_test:
log.info("=====")
log.info("===== Building OpenCV.js tests")
log.info("=====")
builder.build_test()
if args.build_doc:
log.info("=====")
log.info("===== Building OpenCV.js tutorials")
log.info("=====")
builder.build_doc()
log.info("=====")
log.info("===== Build finished")
log.info("=====")
opencvjs_path = os.path.join(builder.build_dir, "bin", "opencv.js")
if check_file(opencvjs_path):
log.info("OpenCV.js location: %s", opencvjs_path)
if args.build_test:
opencvjs_test_path = os.path.join(builder.build_dir, "bin", "tests.html")
if check_file(opencvjs_test_path):
log.info("OpenCV.js tests location: %s", opencvjs_test_path)
if args.build_doc:
opencvjs_tutorial_path = find_file("tutorial_js_root.html", os.path.join(builder.build_dir, "doc", "doxygen", "html"))
if check_file(opencvjs_tutorial_path):
log.info("OpenCV.js tutorials location: %s", opencvjs_tutorial_path)