本文介绍了OpenCV的Andr​​oid上 - 接头;没有这样的文件/目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我是新来使用JNI为Android很抱歉提前如果这是愚蠢的。我已经安装了SDK,并在Eclipse中已经增加一条,作为该项目的库。整理好一切后,我试图运行NDK建造的功能,但得到这个错误:

  ++编译大拇指:face_detect_rec< = jni_part.cpp
在文件中包括来自JNI / face_detect_rec.h:11:0,
                 从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:致命错误:算法:没有这样的文件或目录
编译终止。
使:*** [OBJ /本地/ armeabi / OBJ文件/ face_detect_rec / jni_part.o]错误1
 

这是文件的位置是哪里core.hpp是,所以我不知道为什么这是一个问题。我会后我的code如下,仅供参考,谢谢你们!

jni_part.cpp:

 的#include< jni.h>
#包括face_detect_rec.h

使用名字空间std;
使用命名空间的简历;

为externC{


JNIEXPORT无效JNICALL Java_com_example_opencvandroidtest_MainActivity_detectFaces(
        JNIEnv的* ENV,JCLASS mClass,文件路径的jstring)
{
    detectFaces(文件路径);
}
}
 

face_detect_rec.h

 的#include< stdio.h中>
#包括< stdlib.h中>
#包括< string.h中>
#包括< ASSERT.H>
#包括<文件math.h>
#包括< FLOAT.H>
#包括< limits.h中>
#包括< time.h中>
#包括<文件ctype.h>

#包括< opencv2 /核心/ core.hpp>
#包括< opencv2 /一下HighGUI / highgui.hpp>
#包括< opencv2 /的contrib / contrib.hpp>
#包括<的iostream>
#包括< fstream的>
#包括< sstream>
#包括<字符串>

使用命名空间的简历;
使用名字空间std;

静态无效detectFaces(字符串文件路径);
 

face_detect_rec.cpp:

 的#includeface_detect_rec.h
//创建一个包含准确的级联名称的字符串
串faceCascade_name =
        /Users/Justin/Documents/OpenCV/data/haarcascades/haarcascade_frontalface_alt2.xml;
/ *haarcascade_profileface.xml; * /
串eyeCascade_name =
        /Users/Justin/Documents/OpenCV/data/haarcascades/haarcascade_mcs_lefteye.xml;
//字符串rightEyeCascade_name =
///Users/Justin/Documents/OpenCV/data/haarcascades/haarcascade_mcs_righteye.xml;


//功能检测并得出任何面孔是present在图像
静态无效detectFaces(字符串文件路径)
{
    //创建一个新的Haar分类
    CascadeClassifier faceCascade;
    垫IMG = imread(文件路径);

    // int标= 1;

    //将HaarClassifierCascade
    faceCascade.load(faceCascade_name);

    //检查梯级是否已成功加载。否则报告错误并退出
    如果(faceCascade.empty())
    {
        COUT<< 错误:无法加载分类器级联\ N的;
        返回;
    }

    //可以有一个图像多张人脸。因此,创建面可增长的序列。
    //检测对象,并将它们存储在序列中
    矢量<矩形>面临着;
    faceCascade.detectM​​ultiScale(IMG,面孔,1.1,2,CV_HAAR_SCALE_IMAGE,cvSize(70,70));

    //循环发现面的数量。
    的for(int i = 0; I< faces.size();我++)
    {
        //保存图像
        垫faceROI = IMG(面孔[I]);
        stringstream的S;
        S<< 到/ mnt / SD卡/图片/ TagSense<< I<< .JPG;
        imwrite(s.str(),faceROI);
    }
}
}
 

解决方案

你有没有在你的JNI目录中的所谓Application.mk文件?如果你不这样做,尝试与创建它,比如,下面的code:

Application.mk

  APP_STL:= gnustl_static
APP_CPPFLAGS:= -frtti -fexceptions
APP_ABI:= armeabi-V7A
APP_PLATFORM:=机器人-8
 

希望这会有所帮助。

so I am new to using the JNI for Android so sorry in advance if this is something silly. I have installed the SDK and in Eclipse have added it as a library for the project. After finishing up everything, I have tried to run the ndk-build function but get this error:

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

That file location is where the core.hpp is so I am not sure why this is a problem. I'll post my code below for reference, thanks guys!

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);
    }
}
}
解决方案

Do you have a so-called "Application.mk" file in your "jni" directory? If you don't, try to create it with, for instance, the following code:

Application.mk:

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

Hope this will help.

这篇关于OpenCV的Andr​​oid上 - 接头;没有这样的文件/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:31