簡體   English   中英

在 Android NDK 中編譯 OpenCV

[英]Compiling OpenCV in Android NDK

請查看底部的添加內容! 第一個問題在Linux下解決了,在Windows和Cygwin下還沒有解決,但是又出現了一個新問題。 請看下面!

我目前正在嘗試為 Android NDK 編譯 OpenCV,以便我可以在我的應用程序中使用它。 為此,我嘗試遵循本指南:

http://www.stanford.edu/~zxwang/android_opencv.html

但是當用 ndk-build 編譯下載的東西時,我得到這個錯誤:

$ /cygdrive/u/flori/workspace/android-ndk-r5b/ndk-build
Compile++ thumb  : opencv <= cvjni.cpp
Compile++ thumb  : cxcore <= cxalloc.cpp
Compile++ thumb  : cxcore <= cxarithm.cpp
Compile++ thumb  : cxcore <= cxarray.cpp
Compile++ thumb  : cxcore <= cxcmp.cpp
Compile++ thumb  : cxcore <= cxconvert.cpp
Compile++ thumb  : cxcore <= cxcopy.cpp
Compile++ thumb  : cxcore <= cxdatastructs.cpp
Compile++ thumb  : cxcore <= cxdrawing.cpp
Compile++ thumb  : cxcore <= cxdxt.cpp
Compile++ thumb  : cxcore <= cxerror.cpp
Compile++ thumb  : cxcore <= cximage.cpp
Compile++ thumb  : cxcore <= cxjacobieigens.cpp
Compile++ thumb  : cxcore <= cxlogic.cpp
Compile++ thumb  : cxcore <= cxlut.cpp
Compile++ thumb  : cxcore <= cxmathfuncs.cpp
Compile++ thumb  : cxcore <= cxmatmul.cpp
Compile++ thumb  : cxcore <= cxmatrix.cpp
Compile++ thumb  : cxcore <= cxmean.cpp
Compile++ thumb  : cxcore <= cxmeansdv.cpp
Compile++ thumb  : cxcore <= cxminmaxloc.cpp
Compile++ thumb  : cxcore <= cxnorm.cpp
Compile++ thumb  : cxcore <= cxouttext.cpp
Compile++ thumb  : cxcore <= cxpersistence.cpp
Compile++ thumb  : cxcore <= cxprecomp.cpp
Compile++ thumb  : cxcore <= cxrand.cpp
Compile++ thumb  : cxcore <= cxsumpixels.cpp
Compile++ thumb  : cxcore <= cxsvd.cpp
Compile++ thumb  : cxcore <= cxswitcher.cpp
Compile++ thumb  : cxcore <= cxtables.cpp
Compile++ thumb  : cxcore <= cxutils.cpp
StaticLibrary  : libstdc++.a
StaticLibrary  : libcxcore.a
Compile++ thumb  : cv <= cvaccum.cpp
Compile++ thumb  : cv <= cvadapthresh.cpp
Compile++ thumb  : cv <= cvapprox.cpp
Compile++ thumb  : cv <= cvcalccontrasthistogram.cpp
Compile++ thumb  : cv <= cvcalcimagehomography.cpp
Compile++ thumb  : cv <= cvcalibinit.cpp
Compile++ thumb  : cv <= cvcalibration.cpp
Compile++ thumb  : cv <= cvcamshift.cpp
Compile++ thumb  : cv <= cvcanny.cpp
Compile++ thumb  : cv <= cvcolor.cpp
Compile++ thumb  : cv <= cvcondens.cpp
Compile++ thumb  : cv <= cvcontours.cpp
Compile++ thumb  : cv <= cvcontourtree.cpp
Compile++ thumb  : cv <= cvconvhull.cpp
Compile++ thumb  : cv <= cvcorner.cpp
Compile++ thumb  : cv <= cvcornersubpix.cpp
Compile++ thumb  : cv <= cvderiv.cpp
Compile++ thumb  : cv <= cvdistransform.cpp
Compile++ thumb  : cv <= cvdominants.cpp
Compile++ thumb  : cv <= cvemd.cpp
Compile++ thumb  : cv <= cvfeatureselect.cpp
Compile++ thumb  : cv <= cvfilter.cpp
Compile++ thumb  : cv <= cvfloodfill.cpp
Compile++ thumb  : cv <= cvfundam.cpp
Compile++ thumb  : cv <= cvgeometry.cpp
Compile++ thumb  : cv <= cvhaar.cpp
Compile++ thumb  : cv <= cvhistogram.cpp
Compile++ thumb  : cv <= cvhough.cpp
Compile++ thumb  : cv <= cvimgwarp.cpp
Compile++ thumb  : cv <= cvinpaint.cpp
Compile++ thumb  : cv <= cvkalman.cpp
Compile++ thumb  : cv <= cvlinefit.cpp
Compile++ thumb  : cv <= cvlkpyramid.cpp
Compile++ thumb  : cv <= cvmatchcontours.cpp
Compile++ thumb  : cv <= cvmoments.cpp
Compile++ thumb  : cv <= cvmorph.cpp
Compile++ thumb  : cv <= cvmotempl.cpp
Compile++ thumb  : cv <= cvoptflowbm.cpp
Compile++ thumb  : cv <= cvoptflowhs.cpp
Compile++ thumb  : cv <= cvoptflowlk.cpp
Compile++ thumb  : cv <= cvpgh.cpp
Compile++ thumb  : cv <= cvposit.cpp
Compile++ thumb  : cv <= cvprecomp.cpp
Compile++ thumb  : cv <= cvpyramids.cpp
Compile++ thumb  : cv <= cvpyrsegmentation.cpp
Compile++ thumb  : cv <= cvrotcalipers.cpp
Compile++ thumb  : cv <= cvsamplers.cpp
Compile++ thumb  : cv <= cvsegmentation.cpp
Compile++ thumb  : cv <= cvshapedescr.cpp
Compile++ thumb  : cv <= cvsmooth.cpp
Compile++ thumb  : cv <= cvsnakes.cpp
Compile++ thumb  : cv <= cvstereobm.cpp
Compile++ thumb  : cv <= cvstereogc.cpp
Compile++ thumb  : cv <= cvsubdivision2d.cpp
Compile++ thumb  : cv <= cvsumpixels.cpp
Compile++ thumb  : cv <= cvsurf.cpp
Compile++ thumb  : cv <= cvswitcher.cpp
Compile++ thumb  : cv <= cvtables.cpp
Compile++ thumb  : cv <= cvtemplmatch.cpp
Compile++ thumb  : cv <= cvthresh.cpp
Compile++ thumb  : cv <= cvundistort.cpp
Compile++ thumb  : cv <= cvutils.cpp
StaticLibrary  : libcv.a
SharedLibrary  : libopencv.so
U:/flori/workspace/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebui
lt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-andr
oideabi/bin/ld.exe: cannot find -lcxcore
collect2: ld returned 1 exit status
make: *** [/cygdrive/u/flori/workspace/android/testOpenCV/obj/local/armeabi/libo
pencv.so] Error 1

我正在嘗試在 Windows 系統上使用最新的 NDK 版本編譯它...

有沒有人知道這個鏈接錯誤是什么意思,我能做些什么讓它再次工作?

如果有人可以提供幫助,那就太好了


解決問題后,我發現還有另一種編譯 OpenCV for Android 的方法,使用當前版本的 OpenCV(而不是上面的 1.1 版本)和來自 Crystax 的修改后的 Android NDK,它支持 STL 和異常,因此支持最新的 OpenCV 版本。

可以在此處找到所有相關信息: http : //opencv.willowgarage.com/wiki/Android

那里說要下載當前的 svn 主干和 crystax-r4 android-ndk,以及 swig,我就是這樣做的。

我進入文件夾,創建構建目錄,運行 cmake,然后構建靜態庫,這似乎有效。 至少它成功地運行了 make-command 沒有錯誤。

我現在想構建共享庫,所以我進入了 android-jni 文件夾並再次運行“make”,但得到了這個錯誤:

% make -j4
OPENCV_CONFIG = ../build/android-opencv.mk
make clean-swig &&\
    mkdir -p jni/gen &&\
    mkdir -p src/com/opencv/jni &&\
    swig -java -c++ -package "com.opencv.jni" \
    -outdir src/com/opencv/jni \
    -o jni/gen/android_cv_wrap.cpp jni/android-cv.i
OPENCV_CONFIG = ../build/android-opencv.mk
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make[1]: warning: jobserver unavailable: using -j1.  Add `+' to parent make rule.
rm -f  jni/gen/android_cv_wrap.cpp
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
    PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V= 
/home/florian/android-ndk-r4-crystax/ndk-build OPENCV_CONFIG=../build/android-opencv.mk \
    PROJECT_PATH= ARM_TARGETS="armeabi armeabi-v7a" V= 
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: Entering directory `/home/florian/android-opencv-willowgarage/android/android-jni'
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: warning: jobserver unavailable: using -j1.  Add `+' to parent make rule.
/home/florian/android-opencv-willowgarage/android/android-jni/jni/Android.mk:10: ../build/android-opencv.mk: No such file or directory
make[1]: *** No rule to make target `../build/android-opencv.mk'.  Stop.
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make: *** [libs/armeabi/libandroid-opencv.so] Error 2
make: *** Waiting for unfinished jobs....
make[1]: warning: jobserver unavailable: using -j1.  Add `+' to parent make rule.
make[1]: *** No rule to make target `../build/android-opencv.mk'.  Stop.
make[1]: Leaving directory `/home/florian/android-opencv-willowgarage/android/android-jni'
make: *** [libs/armeabi-v7a/libandroid-opencv.so] Error 2

有沒有人知道這意味着什么以及我可以做什么來構建共享庫?

...

好的,在查看了錯誤消息后,我發現構建目錄中似乎缺少某些內容……但 android 文件夾中甚至沒有構建目錄,所以我創建了一個,在在那里再次“制作”,但出現此錯誤:

Compile thumb  : opencv_lapack <= /home/florian/android-opencv-willowgarage/3rdparty/lapack/sgetrf.c
Compile thumb  : opencv_lapack <= /home/florian/android-opencv-willowgarage/3rdparty/lapack/scopy.c
Compile++ thumb: opencv_core <= /home/florian/android-opencv-willowgarage/modules/core/src/matrix.cpp
cc1plus: error: /home/florian/android-opencv-willowgarage/android/../modules/index.rst/include: Not a directory
make[3]: *** [/home/florian/android-opencv-willowgarage/android/build/obj/local/armeabi/objs/opencv_core/src/matrix.o] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [android-opencv] Error 2
make[1]: *** [CMakeFiles/ndk.dir/all] Error 2
make: *** [all] Error 2

有人知道這是什么意思嗎?

我剛剛在 Linux 上用 ndk-r5b 構建了它。 您的項目目錄(不是jni )中是否有一個default.properties文件,其內容類似於以下內容:

target=android-8

如果沒有,您可以嘗試創建它並重新構建。

在 cygwin 的情況下,標准的 gcc 規范文件包含 -dll-search-prefix=cyg,因此實際上我們實際上搜索的是 cygxxx.dll。 (不適用於 libcxcore.a)所以您需要將 libxxx.a 復制到 cygxxx.a 並將它們放在一些可用於鏈接器的目錄中。 我在http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Using_ld_the_GNU_Linker/win32.html 上找到了這個解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM