2013-02-24 29 views
3

所以我是新的使用Android的JNI,所以如果這是愚蠢的事先提前對不起。我已經安裝了SDK,並在Eclipse中添加了它作爲該項目的庫。完成了一切之後,我試圖運行NDK建造功能,但得到這個錯誤:Android上的OpenCV - 標題;沒有這樣的文件/目錄

Compile++ thumb : face_detect_rec <= jni_part.cpp 
In file included from jni/face_detect_rec.h:11:0, 
       from jni/jni_part.cpp:3: 
/Users/Justin/Documents/Android/opencv-2.4.3.2-android-sdk/sdk/native/jni/include/opencv2/core/core.hpp:56:21: fatal error: algorithm: No such file or directory 
compilation terminated. 
make: *** [obj/local/armeabi/objs/face_detect_rec/jni_part.o] Error 1 

該文件位置是在core.hpp是,所以我不知道爲什麼,這是一個問題。我將在下面發佈我的代碼以供參考,謝謝你們!

jni_part.cpp:

#include <jni.h> 
#include "face_detect_rec.h" 

using namespace std; 
using namespace cv; 

extern "C" { 


JNIEXPORT void JNICALL Java_com_example_opencvandroidtest_MainActivity_detectFaces(
     JNIEnv* env, jclass mClass, jstring filePath) 
{ 
    detectFaces(filePath); 
} 
} 

face_detect_rec.h

#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <assert.h> 
#include <math.h> 
#include <float.h> 
#include <limits.h> 
#include <time.h> 
#include <ctype.h> 

#include <opencv2/core/core.hpp> 
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/contrib/contrib.hpp> 
#include <iostream> 
#include <fstream> 
#include <sstream> 
#include <string> 

using namespace cv; 
using namespace std; 

static void detectFaces(string filePath); 

face_detect_rec.cpp:

#include "face_detect_rec.h" 
// Create a string that contains the exact cascade name 
string faceCascade_name = 
     "/Users/Justin/Documents/OpenCV/data/haarcascades/haarcascade_frontalface_alt2.xml"; 
/* "haarcascade_profileface.xml";*/ 
string eyeCascade_name = 
     "/Users/Justin/Documents/OpenCV/data/haarcascades/haarcascade_mcs_lefteye.xml"; 
//string rightEyeCascade_name = 
// "/Users/Justin/Documents/OpenCV/data/haarcascades/haarcascade_mcs_righteye.xml"; 


// Function to detect and draw any faces that is present in an image 
static void detectFaces(string filePath) 
{ 
    // Create a new Haar classifier 
    CascadeClassifier faceCascade; 
    Mat img = imread(filePath); 

    //int scale = 1; 

    // Load the HaarClassifierCascade 
    faceCascade.load(faceCascade_name); 

    // Check whether the cascade has loaded successfully. Else report and error and quit 
    if(faceCascade.empty()) 
    { 
     cout << "ERROR: Could not load classifier cascade\n"; 
     return; 
    } 

    // There can be more than one face in an image. So create a growable sequence of faces. 
    // Detect the objects and store them in the sequence 
    vector<Rect> faces; 
    faceCascade.detectMultiScale(img, faces, 1.1, 2, CV_HAAR_SCALE_IMAGE, cvSize(70, 70)); 

    // Loop the number of faces found. 
    for(int i=0; i<faces.size(); i++) 
    { 
     //save image 
     Mat faceROI = img(faces[i]); 
     stringstream s; 
     s << "/mnt/sdcard/Pictures/TagSense" << i << ".jpg"; 
     imwrite(s.str(), faceROI); 
    } 
} 
} 

回答

9

你有一個所謂的 「Application.mk」 文件你的「jni」目錄?如果不這樣做,嘗試與創建它,例如,下面的代碼:

Application.mk

APP_STL := gnustl_static 
APP_CPPFLAGS := -frtti -fexceptions 
APP_ABI := armeabi-v7a 
APP_PLATFORM := android-8 

希望這會有所幫助。

+1

這樣做的伎倆,自己弄明白了,但從來沒有機會回答自己。任何想法的原因? – justbaum30 2013-03-04 19:15:15

+1

在OpenCV文檔中,他們提到了STL:「通常文件Application.mk是可選的,但在使用OpenCV的項目中,當在C++中使用STL和異常時,它也應該被創建。參考:http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/android_dev_intro.html – JonesV 2013-03-05 19:20:54

相關問題