Skip to content

Commit cc5f4c2

Browse files
committed
Merge pull request kivy#327 from jasonxunxu/recipe-opencv
Recipe for OpenCV
2 parents 0db672d + 33c5b77 commit cc5f4c2

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
diff --git a/cmake/OpenCVDetectPython.cmake b/cmake/OpenCVDetectPython.cmake
2+
index 31c2c1e..c890917 100644
3+
--- a/cmake/OpenCVDetectPython.cmake
4+
+++ b/cmake/OpenCVDetectPython.cmake
5+
@@ -36,7 +36,7 @@ if(PYTHON_EXECUTABLE)
6+
unset(PYTHON_VERSION_FULL)
7+
endif()
8+
9+
- if(NOT ANDROID AND NOT IOS)
10+
+ if(P4A OR NOT ANDROID AND NOT IOS)
11+
ocv_check_environment_variables(PYTHON_LIBRARY PYTHON_INCLUDE_DIR)
12+
if(CMAKE_CROSSCOMPILING)
13+
find_host_package(PythonLibs ${PYTHON_VERSION_MAJOR_MINOR})
14+
@@ -51,7 +51,7 @@ if(PYTHON_EXECUTABLE)
15+
endif()
16+
endif()
17+
18+
- if(NOT ANDROID AND NOT IOS)
19+
+ if(P4A OR NOT ANDROID AND NOT IOS)
20+
if(CMAKE_HOST_UNIX)
21+
execute_process(COMMAND ${PYTHON_EXECUTABLE} -c "from distutils.sysconfig import *; print get_python_lib()"
22+
RESULT_VARIABLE PYTHON_CVPY_PROCESS
23+
@@ -117,7 +117,7 @@ if(PYTHON_EXECUTABLE)
24+
OUTPUT_STRIP_TRAILING_WHITESPACE)
25+
endif()
26+
endif()
27+
- endif(NOT ANDROID AND NOT IOS)
28+
+ endif(P4A OR NOT ANDROID AND NOT IOS)
29+
30+
if(BUILD_DOCS)
31+
find_host_program(SPHINX_BUILD sphinx-build)
32+
diff --git a/modules/python/CMakeLists.txt b/modules/python/CMakeLists.txt
33+
index 3c0f2fd..7ba234a 100644
34+
--- a/modules/python/CMakeLists.txt
35+
+++ b/modules/python/CMakeLists.txt
36+
@@ -5,7 +5,7 @@
37+
if(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "Debug")
38+
ocv_module_disable(python)
39+
endif()
40+
-if(ANDROID OR IOS OR NOT PYTHONLIBS_FOUND OR NOT PYTHON_USE_NUMPY)
41+
+if(ANDROID AND NOT P4A OR IOS OR NOT PYTHONLIBS_FOUND OR NOT PYTHON_USE_NUMPY)
42+
ocv_module_disable(python)
43+
endif()
44+
45+
diff --git a/modules/androidcamera/src/camera_activity.cpp b/modules/androidcamera/src/camera_activity.cpp
46+
index 84db3e1..4222526 100644
47+
--- a/modules/androidcamera/src/camera_activity.cpp
48+
+++ b/modules/androidcamera/src/camera_activity.cpp
49+
@@ -7,6 +7,7 @@
50+
#include <string>
51+
#include <vector>
52+
#include <algorithm>
53+
+#include <stdlib.h>
54+
#include <opencv2/core/version.hpp>
55+
#include "camera_activity.hpp"
56+
#include "camera_wrapper.h"
57+
@@ -342,6 +343,8 @@ std::string CameraWrapperConnector::getPathLibFolder()
58+
59+
char* pathEnd = strrchr(pathBegin, '/');
60+
pathEnd[1] = 0;
61+
+ pathBegin = realpath((std::string(pathBegin)+"../../../../lib").c_str(), lineBuf);
62+
+ pathBegin = strcat(pathBegin, "/");
63+
64+
LOGD("Libraries folder found: %s", pathBegin);
65+

recipes/opencv/recipe.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
3+
VERSION_opencv=${VERSION_opencv:-2.4.10.1}
4+
URL_opencv=https://github.com/Itseez/opencv/archive/$VERSION_opencv.zip
5+
6+
DEPS_opencv=(numpy python)
7+
MD5_opencv=e6667a39c33aa2c63defb9beb94e84ca
8+
BUILD_opencv=$BUILD_PATH/opencv/$(get_directory $URL_opencv)
9+
RECIPE_opencv=$RECIPES_PATH/opencv
10+
11+
_cvsrc=$BUILD_opencv
12+
_cvbuild=$BUILD_opencv/build_p4a
13+
_pyroot=$(dirname `dirname $HOSTPYTHON`)
14+
15+
function prebuild_opencv() {
16+
cd $BUILD_opencv
17+
18+
if [ -f .patched ]; then
19+
return
20+
fi
21+
22+
try patch -p1 < $RECIPE_opencv/patches/p4a_build-2.4.10.1.patch
23+
touch .patched
24+
}
25+
26+
function shouldbuild_opencv() {
27+
if [ -f "$SITEPACKAGES_PATH/cv2.so" ]; then
28+
DO_BUILD=0
29+
fi
30+
}
31+
32+
function build_opencv() {
33+
34+
try mkdir -p $_cvbuild
35+
cd $_cvbuild
36+
37+
push_arm
38+
#try set > opencv_p4y_env.log # check env vars for debugging
39+
40+
export ANDROID_NDK=$ANDROIDNDK
41+
try cmake -DP4A=ON -DANDROID_ABI=$ARCH -DCMAKE_TOOLCHAIN_FILE=$_cvsrc/platforms/android/android.toolchain.cmake \
42+
-DPYTHON_INCLUDE_PATH=$_pyroot/include/python2.7 -DPYTHON_LIBRARY=$_pyroot/lib/libpython2.7.so \
43+
-DPYTHON_NUMPY_INCLUDE_DIR=$SITEPACKAGES_PATH/numpy/core/include \
44+
-DANDROID_EXECUTABLE=$ANDROIDSDK/tools/android \
45+
-DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=OFF \
46+
-DPYTHON_PACKAGES_PATH=$SITEPACKAGES_PATH \
47+
$_cvsrc
48+
try make -j8 opencv_python
49+
try cmake -DCOMPONENT=python -P ./cmake_install.cmake
50+
try cp -a $_cvbuild/lib/$ARCH/lib*.so $LIBS_PATH
51+
52+
pop_arm
53+
}
54+
55+
function postbuild_opencv() {
56+
true
57+
}

0 commit comments

Comments
 (0)