Skip to content

Commit 0d8967d

Browse files
author
EC2 Default User
committed
Init
1 parent 251ef0a commit 0d8967d

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

build.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Setting up build env
4+
yum update -y
5+
yum install -y git cmake gcc-c++ gcc python-devel chrpath
6+
mkdir lambda-package build
7+
8+
# Build numpy
9+
pip install --install-option="--prefix=$PWD/build" numpy
10+
mv build/lib64/python2.7/site-packages/numpy lambda-package
11+
12+
# Build OpenCV 3.1
13+
(
14+
NUMPY=$PWD/lambda-package/numpy/core/include
15+
cd build
16+
git clone https://github.com/Itseez/opencv.git
17+
cd opencv
18+
git checkout 3.1.0
19+
cmake \
20+
-D CMAKE_BUILD_TYPE=RELEASE \
21+
-D WITH_TBB=ON \
22+
-D WITH_IPP=ON \
23+
-D WITH_V4L=ON \
24+
-D ENABLE_AVX=ON \
25+
-D ENABLE_SSE42=ON \
26+
-D ENABLE_POPCNT=ON \
27+
-D ENABLE_FAST_MATH=ON \
28+
-D BUILD_EXAMPLES=OFF \
29+
-D PYTHON2_NUMPY_INCLUDE_DIRS="$NUMPY" \
30+
.
31+
make
32+
)
33+
mkdir lambda-package/cv2
34+
cp `find opencv/lib "*.so*" -type f` lambda-package/cv2
35+
strip --strip-all lambda-package/cv2/*
36+
chrpath -r '$ORIGIN' lambda-package/cv2/cv2.so
37+
cp ressources/__init.py__ lambda-package/cv2
38+
39+
# Copy template function and zip package
40+
cp ressources/template.py lambda-package/lambda_function.py
41+
zip -r lambda-package.zip lambda-package/*

ressources/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pkg_resources
2+
import imp
3+
4+
__file__ = pkg_resources.resource_filename(__name__, "cv2.so")
5+
imp.load_dynamic(__name__, __file__)

ressources/template.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import cv2
2+
3+
def lambda_handler(event, context):
4+
print "OpenCV installed version:", cv2.__version__
5+
return "It works!"
6+
7+
if __name__ == "__main__":
8+
lambda_handler(42, 42)

0 commit comments

Comments
 (0)