5

我已经下载了适用于 android 的 OpenCV 项目,并且随附的示例项目包含几个错误.. 只有包含 NDK 代码的项目有错误.. 问题是 C++ 代码显示了很多错误.. .jstring之类的关键字无法识别..请帮我解决这个问题...提前感谢您的宝贵时间

#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
4

2 回答 2

4

@Nolan 的回答和@Michael 的评论为我解决了这个问题。以下是合并的步骤:

  1. 在 Eclipse 中,右键单击您的项目并选择属性(这是在 mac btw 上)
  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++ Build - Environment下添加它

  7. 现在继续并通过右键单击您的项目并选择索引来重建索引 - 重建

干杯。

于 2013-04-03T14:21:31.313 回答
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
于 2012-09-16T19:45:24.193 回答