2012-07-27 41 views
5

我已经下载了OpenCV项目的android和与它捆绑在一起的示例项目包含几个错误.... 只有包含NDK代码的项目有错误.... 问题是,C++代码展示了许多错误...... 喜欢的jstring关键字不认可.. 请帮我解决这个问题... 请多关照您的宝贵时间OpenCV for android示例程序显示错误

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

using namespace std; 
using namespace cv; 

extern "C" { 
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3View_FindFeatures(JNIEnv* env, jobject, jint width, jint height, jbyteArray yuv, jintArray bgra) 
{ 
    jbyte* _yuv = env->GetByteArrayElements(yuv, 0); 
    jint* _bgra = env->GetIntArrayElements(bgra, 0); 

    Mat myuv(height + height/2, width, CV_8UC1, (unsigned char *)_yuv); 
    Mat mbgra(height, width, CV_8UC4, (unsigned char *)_bgra); 
    Mat mgray(height, width, CV_8UC1, (unsigned char *)_yuv); 

    //Please make attention about BGRA byte order 
    //ARGB stored in java as int array becomes BGRA at native level 
    cvtColor(myuv, mbgra, CV_YUV420sp2BGR, 4); 

    vector<KeyPoint> v; 

    FastFeatureDetector detector(50); 
    detector.detect(mgray, v); 
    for(size_t i = 0; i < v.size(); i++) 
     circle(mbgra, Point(v[i].pt.x, v[i].pt.y), 10, Scalar(0,0,255,255)); 

    env->ReleaseIntArrayElements(bgra, _bgra, 0); 
    env->ReleaseByteArrayElements(yuv, _yuv, 0); 
} 

} 

错误..

Unresolved inclusion: <vector> 
Symbol 'std' could not be resolved 
+0

您应该发布错误消息和它们对应的代码。 – Michael 2012-07-27 08:45:10

+0

@Michael ...请参阅编辑.. – 2012-07-27 08:59:05

+0

您使用的是Eclipse吗?如果是这样,你有没有试过这个:http://stackoverflow.com/questions/9375708/eclipse-indexer-errors-when-using-stl-with-android-ndk? – Michael 2012-07-27 09:08:50

回答

0

我有同样的问题,并能同时使用以下路径下OpenCV的教程来解决这些和遇到其他错误:

${NDKROOT}/platforms/android-9/arch-arm/usr/include 
${ProjDirPath}/../../sdk/native/jni/include 
${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/include 
${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/include 
4

@诺兰的回答跟@迈克尔的意见解决了这个问题对我来说。以下是合并步骤:

  1. 在Eclipse中,右键点击你的项目,并选择属性(这是顺便说一句的是Mac)
  2. 展开C/C++通用
  3. 选择路径和符号
  4. 语言选择GNU C++
  5. 以下包括应该下定义包含目录

    ${NDKROOT}/platforms/android-9/arch-arm/usr/include 
    ${ProjDirPath}/../../sdk/native/jni/include 
    ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/libs/armeabi-v7a/include 
    ${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.4.3/include 
    
  6. 确保$ {} NDKROOT被定义为环境变量。如果它不继续前进,添加它下C/C++编译 - 环境

  7. 现在继续重建右击该指数在你的项目,并选择指数 - 重建

干杯。