Sreekanth Karumanaghat
Sreekanth Karumanaghat

Reputation: 3403

OpenCV for android sample programs showing error

I have downloaded OpenCV project for android and the sample projects that came bundled with it contains several errors.... Only the projects that contain the NDK code has the errors.... The problem is that the C++ code shows many errors... The keywords like jstring are not recognised.. Kindly help me resolve this issue... Thanking you in advance for your valuable time

#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);
}

}

errors..

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

Upvotes: 5

Views: 4654

Answers (2)

user604919
user604919

Reputation:

@Nolan's answer followed by @Michael's comment solved it for me. Here are the combined steps:

  1. In Eclipse, right click on your project and select properties (This is on a mac btw)
  2. Expand C/C++ General
  3. Select Paths and Symbols
  4. Under Languages select GNU C++
  5. The following includes should be defined under Include directories

    ${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. Make sure ${NDKROOT} is defined as an environment variable. If it's not go ahead and add it under C/C++ Build - Environment

  7. Now go ahead and rebuild the index by right clicking on your project and select Index - Rebuild

Cheers.

Upvotes: 4

Nolan Amy
Nolan Amy

Reputation: 11135

I had the same problem and was able to resolve these and other errors encountered while following the OpenCV tutorial by using the following include paths:

${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

Upvotes: 0

Related Questions