android - Android 上的 OpenCV - 标题;没有那个文件/目录

标签 android opencv java-native-interface

所以我是 Android 版 JNI 的新手,如果这有点愚蠢,请提前致歉。我已经安装了 SDK,并在 Eclipse 中将其添加为项目的库。完成所有操作后,我尝试运行 ndk-build 函数但出现此错误:

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

最佳答案

您的“jni”目录中是否有所谓的“Application.mk”文件?如果您不这样做,请尝试使用例如以下代码创建它:

Application.mk:

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

希望这会有所帮助。

关于android - Android 上的 OpenCV - 标题;没有那个文件/目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15054666/

相关文章:

android - Android 中的 Windows 身份验证

c++ - QT实时摄像机显示由于内存不足而崩溃

python - python中的不规则区域掩码

java - 我怎样才能解决 CLASSPATH 问题并在 OSX 上编译 OpenKinect Java 示例?

java - Opencv 将 Mat 从 Android 传递到 JNI 错误

java - 在 Java 中从内存中执行一个可执行程序(.exe)

java - 如何知道 BLE 设备何时订阅了 Android 上的特征?

java - 尝试在我的录音机的同一按钮上实现播放/暂停功能

php - 如何将 php time() 转换为 android 时间戳?

c++ - MATLAB BWLABEL 的 OpenCV 替代品