diff --git a/README.md b/README.md index 330933b..5fb245e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is a JavaScript binding that exposes OpenCV library to the web. This project is made possible by support of Intel corporation. Currently, this is based on OpenCV 3.1.0. -### How to Build +### How to Build with Javascript Bindings 1. Get the source code ``` @@ -36,6 +36,18 @@ This is a JavaScript binding that exposes OpenCV library to the web. This projec python make.py ``` +### How to Build static C++ library/headers that works with existing emscripten projects +1. Follow steps 1 and 2 above. + +2. Compile OpenCV and generate bindings by executing make.py script. + + ``` + python make.py --build-static-lib + ``` + +3. The compiled static libraries will be found in build/lib, headers in build/include and 3rd party libs in build/3rdparty + + ### Tests Test suite contains several tests and examples demonstrating how the API can be used. Run the tests by launching test/tests.html file usig a browser. diff --git a/make.py b/make.py index f05365d..31aab54 100644 --- a/make.py +++ b/make.py @@ -1,6 +1,19 @@ #!/usr/bin/python import os, sys, re, json, shutil from subprocess import Popen, PIPE, STDOUT +from distutils.dir_util import copy_tree +import argparse + +parser = argparse.ArgumentParser(description='Creates javascript bindings for openCV') +parser.add_argument('--build-static-lib', + dest='build_static_lib', + default=False, + const=True, + nargs='?', + help='Only builds openCV static C++ library. For use with exisiting emscripten projects') + +args = parser.parse_args() +build_static_lib = args.build_static_lib # Startup exec(open(os.path.expanduser('~/.emscripten'), 'r').read()) @@ -36,6 +49,7 @@ print print '--------------------------------------------------' print 'Building opencv.js, build type:', emcc_args +print 'Building static C++ lib only:', build_static_lib print '--------------------------------------------------' print @@ -161,7 +175,8 @@ def stage(text): emscripten.Building.make(['make', '-j4']) - stage('Generating Bindings') + if not build_static_lib: + stage('Generating Bindings') INCLUDE_DIRS = [ os.path.join('..', 'modules', 'core', 'include'), os.path.join('..', 'modules', 'flann', 'include'), @@ -180,6 +195,35 @@ def stage(text): emcc_binding_args = ['--bind'] emcc_binding_args += include_dir_args + if build_static_lib: + includes_dir = os.path.join('..', '..', 'build', 'includes', 'opencv2') + lib_dir = os.path.join('..', '..', 'build', 'lib') + thirdparty_lib_dir = os.path.join('..', '..', 'build', '3rdparty', 'lib') + + if not os.path.isdir(includes_dir): + os.makedirs(includes_dir) + + if not os.path.isdir(lib_dir): + os.makedirs(lib_dir) + + if not os.path.isdir(thirdparty_lib_dir): + os.makedirs(thirdparty_lib_dir) + + for path in INCLUDE_DIRS: + if os.path.isdir(path): + print "Copying", path, "to", includes_dir + copy_tree(os.path.join(path, 'opencv2'), includes_dir) + + lib = os.path.join('lib') + print "Copying", lib, "to", lib_dir + copy_tree(lib, lib_dir) + + thirdparty = os.path.join('3rdparty', 'lib') + print "Copying", thirdparty, "to", thirdparty_lib_dir + copy_tree(thirdparty, thirdparty_lib_dir) + + sys.exit() + emscripten.Building.emcc('../../bindings.cpp', emcc_binding_args, 'bindings.bc') assert os.path.exists('bindings.bc')