2012-07-27 40 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. 現在繼續重建右擊該指數在你的項目,並選擇指數 - 重建

乾杯。