简体   繁体   English

OpenCV Android NDK项目将无法构建

[英]OpenCV Android NDK Project will not build

I am using OpenCV 2.4.4 with Eclipse Juno on Ubuntu. 我在Ubuntu上使用OpenCV 2.4.4和Eclipse Juno。 My problem is similar to this one OpenCV for android sample programs showing error 我的问题类似于这个OpenCV for android示例程序显示错误

But is now weirding me out. 但是现在正在把我赶出去。 I spent most of my weekend trying to get the ndk and opencv library to play nice and still I cannot get it to work. 我周末的大部分时间都在努力让ndk和opencv库发挥得很好,但我仍然无法让它工作。 I have in my test C++ cpp file with the following includes - 我在我的测试C ++ cpp文件中包括以下内容 -

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <cstdlib>

using namespace cv; //this is a problem
...
...

And it tells me when I try to build that "namespace cv cannot be found". 它告诉我,当我尝试构建“无法找到命名空间cv”时。 Oh well, I must have written some path wrong or am not using the correct library, right? 哦,我必须写错路径或者没有使用正确的库,对吧? Wrong. 错误。 In the terminal, ndk-build builds the .so files without any errors. 在终端中, ndk-build构建.so文件没有任何错误。 I can see them plain as day in the project folder. 我可以在项目文件夹中看到它们。 But if I try to do build in eclipse, ie build the apk for tesitng on a virtual device or real device, then I get the namespace cv error and the build fails and then in the cpp file cv is underlined red and in eclipse the file is marked red and I can't even attempt to build until this file is "corrected". 但是,如果我尝试在eclipse中构建,即在虚拟设备或真实设备上构建apk for tesitng,那么我得到命名空间cv错误并且构建失败然后在cpp文件中cv加下划线红色并在eclipse文件中被标记为红色,我甚至无法尝试构建,直到此文件被“更正”。

Clearly I'm doing something wrong. 显然,我做错了什么。 But if I close my eclipse project and then reopen it, the cpp file is no longer marked red and I can make an apk build. 但是,如果我关闭我的eclipse项目,然后重新打开它,cpp文件不再标记为红色,我可以进行apk构建。 If I attempt to open the cpp file the red returns and no more builds can happen until I go through the project close/open rigmarole. 如果我尝试打开cpp文件,红色返回,在我完成项目关闭/打开rigmarole之前不会再发生构建。

I honestly don't know what the cause of the problem is. 老实说,我不知道问题的原因是什么。 Any help would be greatly appreciated. 任何帮助将不胜感激。

My android.mk file: 我的android.mk文件:

include $(CLEAR_VARS)


OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=STATIC
include /the/correct/path/tp/opencv/sdk/native/jni/OpenCV.mk 

LOCAL_MODULE    := mylib
LOCAL_SRC_FILES := mylib.cpp
include $(BUILD_SHARED_LIBRARY)

Application.mk Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all #i have tried various targets
APP_PLATFORM := android-8
APP_MODULES := mylib

I didn't think it would be this difficult. 我不认为这会很困难。 I should add that I have successfully used opencv with Android in anothe rproject I built on WIndows with Eclipse 3.5 (I think) and OpenCV 2.4.2 我应该补充一点,我已经成功地将opencv与Android一起用于我使用Eclipse 3.5(我认为)和OpenCV 2.4.2构建在WIndows上的rproject中

EDIT I also want to say that I just did a quick 'n dirty test opencv operation. 编辑我也想说我刚刚做了一个快速的脏测试opencv操作。 I wrote a quick Sobel function and called it as a native function in a Java file and "sobelled" a bitmap successfully. 我写了一个快速的Sobel函数,并将其称为Java文件中的本机函数,并成功地“sobelled”了一个位图。 Of course, I still had to close/open my project to do this. 当然,我仍然必须关闭/打开我的项目才能做到这一点。

Hi I had same problem with you and after I added below "opencv android sdk" path that include problem disappeared. 嗨,我和你有同样的问题,我添加下面的“opencv android sdk”路径,包括问题消失了。

exp : C:\\project\\OpenCV-2.4.6-android-sdk\\sdk\\native\\jni\\include switch the path with your opencv-android-sdk path. exp:C:\\ project \\ OpenCV-2.4.6-android-sdk \\ sdk \\ native \\ jni \\ include用你的opencv-android-sdk路径切换路径。

I know that's maybe too late, but in my case (Windows+Eclipse) I correct this problem just changing the backslash "\\" to slash "/" in the Path and Symbols include of opencv jni libs. 我知道这可能为时已晚,但在我的情况下(Windows + Eclipse)我更正了这个问题,只是将反斜杠“\\”改为斜线“/”在路径和符号包括opencv jni libs中。

Example: Wrong H:\\opencv\\sdk\\native\\jni\\include Correct H:/opencv/sdk/native/jni/include 示例:错误的H:\\ opencv \\ sdk \\ native \\ jni \\ include正确的H:/ opencv / sdk / native / jni / include

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM