Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for building openCV as a library #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

```
Expand Down Expand Up @@ -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.

Expand Down
46 changes: 45 additions & 1 deletion make.py
Original file line number Diff line number Diff line change
@@ -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())
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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'),
Expand All @@ -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')

Expand Down