基于JavaCV的Android人脸检测

基于JavaCV的Android人脸检测,android,face-detection,javacv,Android,Face Detection,Javacv,我正在制作一个人脸检测应用程序(不是实时的),在android上检测图像中的人脸 我尝试在android.media中使用FaceDetector类,这很好,但不是很准确。 所以我下载了JavaCV和java.cpp包 (使用OpenCV v 2.3) 项目运行,但出现例外情况: Thread [<1> main] (Suspended (exception UnsatisfiedLinkError)) Loader.loadLibrary(Class, String[]

我正在制作一个人脸检测应用程序(不是实时的),在android上检测图像中的人脸 我尝试在android.media中使用FaceDetector类,这很好,但不是很准确。 所以我下载了JavaCV和java.cpp包 (使用OpenCV v 2.3) 项目运行,但出现例外情况:

    Thread [<1> main] (Suspended (exception UnsatisfiedLinkError))  
Loader.loadLibrary(Class, String[], String) line: 463   
Loader.load(Class) line: 368    
Loader.load() line: 315 
opencv_core.<clinit>() line: 131    
Class.classForName(String, boolean, ClassLoader) line: not available [native method]    
Class.forName(String, boolean, ClassLoader) line: 234   
Loader.load(Class) line: 334    
opencv_imgproc.<clinit>() line: 96  
Class.classForName(String, boolean, ClassLoader) line: not available [native method]    
Class.forName(String, boolean, ClassLoader) line: 234   
Loader.load(Class) line: 334    
opencv_objdetect.<clinit>() line: 96    
Class.classForName(String, boolean, ClassLoader) line: not available [native method]    
Class.forName(String, boolean, ClassLoader) line: 234   
Loader.load(Class) line: 334    
MyView.<init>(Context) line: 50 
FaceSwAPPerActivity.onCreate(Bundle) line: 35   
Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047   
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1611    
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1663 
ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 117   
ActivityThread$H.handleMessage(Message) line: 931   
ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
Looper.loop() line: 123 
ActivityThread.main(String[]) line: 3683    
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
Method.invoke(Object, Object...) line: 507  
ZygoteInit$MethodAndArgsCaller.run() line: 839  
ZygoteInit.main(String[]) line: 597 
NativeStart.main(String[]) line: not available [native method]  
Thread[main](挂起(异常未满足LinkError))
loadLibrary(类,字符串[],字符串)行:463
装载机。装载(类)行:368
Loader.load()行:315
opencv_核心。()行:131
classForName(字符串、布尔值、类加载器)行:不可用[本机方法]
forName(字符串、布尔值、类加载器)行:234
装载机。装载(类)行:334
opencv_imgproc.()行:96
classForName(字符串、布尔值、类加载器)行:不可用[本机方法]
forName(字符串、布尔值、类加载器)行:234
装载机。装载(类)行:334
opencv_objdetect.()行:96
classForName(字符串、布尔值、类加载器)行:不可用[本机方法]
forName(字符串、布尔值、类加载器)行:234
装载机。装载(类)行:334
MyView.(上下文)行:50
FaceSwAPPerActivity.onCreate(Bundle)行:35
检测.callActivityOnCreate(活动,捆绑)行:1047
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord,Intent)行:1611
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord,Intent)行:1663
ActivityThread.access$1500(ActivityThread,ActivityThread$ActivityClientRecord,Intent)行:117
ActivityThread$H.handleMessage(消息)行:931
ActivityThread$H(处理程序)。dispatchMessage(消息)行:99
Looper.loop()行:123
ActivityThread.main(字符串[])行:3683
invokenactive(Object,Object[],Class,Class[],Class,int,boolean)行:不可用[本机方法]
调用(对象,对象…)行:507
ZygoteInit$MethodAndArgsCaller.run()行:839
颧骨单位。主(字符串[])行:597
NativeStart.main(字符串[])行:不可用[本机方法]
下面是我的代码:

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.View;

import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.cpp.opencv_objdetect;
import com.googlecode.javacv.cpp.opencv_objdetect.*;
import com.googlecode.javacv.cpp.opencv_core.*;

import static com.googlecode.javacv.cpp.opencv_core.cvGetSeqElem;
import static com.googlecode.javacv.cpp.opencv_core.cvRectangle;
import static com.googlecode.javacv.cpp.opencv_core.cvPoint;
import static com.googlecode.javacv.cpp.opencv_objdetect.cvHaarDetectObjects;
import static com.googlecode.javacv.cpp.opencv_core.cvLoad;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvCvtColor;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_BGR2GRAY;
import static com.googlecode.javacv.cpp.opencv_core.CV_AA;
import static com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U;

public class FaceSwAPPerActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setContentView(new MyView(this));
}

}
// The cascade definition to be used for detection.
//private static final String CASCADE_FILE = "haarcascade_frontalface_alt.xml";

class MyView extends View {

  Bitmap myBitmap;

public MyView(Context context) 
    {
        super(context);

         Loader.load(opencv_objdetect.class);

         String CASCADE_FILE = "../haarcascade_frontalface_alt.xml";
         BitmapFactory.Options bitmapFatoryOptions=new BitmapFactory.Options();
            bitmapFatoryOptions.inPreferredConfig=Bitmap.Config.ARGB_8888;
         myBitmap=BitmapFactory.decodeResource(getResources(), R.drawable.kidsparty, bitmapFatoryOptions);

        // Load the original image.
         IplImage originalImage = IplImage.create(200, 400, IPL_DEPTH_8U, 1);
        //IplImage originalImage = com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage( imgPath , 1);
        myBitmap.copyPixelsToBuffer(originalImage.getByteBuffer());

        // We need a grayscale image in order to do the recognition, so we
        // create a new image of the same size as the original one.
        IplImage grayImage = IplImage.create(originalImage.width(), originalImage.height(), IPL_DEPTH_8U, 1);

        // We convert the original image to grayscale.
        cvCvtColor(originalImage, grayImage, CV_BGR2GRAY);
        CvMemStorage storage = CvMemStorage.create();

        // We instantiate a classifier cascade to be used for detection, using the cascade definition.
        CvHaarClassifierCascade cascade = new CvHaarClassifierCascade(cvLoad(CASCADE_FILE));

        // We detect the faces.
        CvSeq faces = cvHaarDetectObjects(grayImage, cascade, storage, 1.1, 1, 0);

        //We iterate over the discovered faces and draw yellow rectangles around them.
        for (int i = 0; i < faces.total(); i++) {
          CvRect r = new CvRect(cvGetSeqElem(faces, i));
          cvRectangle(originalImage, cvPoint(r.x(), r.y()),
          cvPoint(r.x() + r.width(), r.y() + r.height()), CvScalar.YELLOW, 1, CV_AA, 0);
        }
        myBitmap.copyPixelsToBuffer(originalImage.getByteBuffer());
        // Save the image to a new file.
       // com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage(args[1], originalImage);
    }
@Override
protected void onDraw(Canvas canvas)
{
    canvas.drawBitmap(myBitmap, 0,0, null);
}

}
导入android.app.Activity;
导入android.content.Context;
导入android.graphics.Bitmap;
导入android.graphics.BitmapFactory;
导入android.graphics.Canvas;
导入android.os.Bundle;
导入android.view.view;
导入com.googlecode.javacpp.Loader;
导入com.googlecode.javacv.cpp.opencv_objdetect;
导入com.googlecode.javacv.cpp.opencv_objdetect.*;
导入com.googlecode.javacv.cpp.opencv_core.*;
导入静态com.googlecode.javacv.cpp.opencv_core.cvgetsequelem;
导入静态com.googlecode.javacv.cpp.opencv_core.cvRectangle;
导入静态com.googlecode.javacv.cpp.opencv_core.cvPoint;
导入静态com.googlecode.javacv.cpp.opencv_objdetect.cvhaardeticobjects;
导入静态com.googlecode.javacv.cpp.opencv_core.cvLoad;
导入静态com.googlecode.javacv.cpp.opencv_imgproc.cvtcolor;
导入静态com.googlecode.javacv.cpp.opencv_imgproc.CV_bgr2;
导入静态com.googlecode.javacv.cpp.opencv_core.CV_AA;
导入静态com.googlecode.javacv.cpp.opencv_core.IPL_DEPTH_8U;
公共类FaceSwaperActivity扩展活动{
/**在首次创建活动时调用*/
@凌驾
创建时的公共void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setContentView(新MyView(this));
}
}
//用于检测的级联定义。
//私有静态最终字符串CASCADE_FILE=“haarcascade_frontalface_alt.xml”;
类MyView扩展了视图{
位图;
公共MyView(上下文)
{
超级(上下文);
load(opencv_objdetect.class);
字符串CASCADE_FILE=“../haarcascade_frontalface_alt.xml”;
选项bitmapFatoryOptions=新的BitmapFactory.Options();
bitmapFatoryOptions.inPreferredConfig=Bitmap.Config.ARGB_8888;
myBitmap=BitmapFactory.decodeResource(getResources(),R.drawable.Kidspatty,bitmapFatoryOptions);
//加载原始图像。
IplImage originalImage=IplImage.create(200400,IPL_DEPTH_8U,1);
//IplImage originalImage=com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage(imgPath,1);
myBitmap.copyPixelsToBuffer(originalImage.getByteBuffer());
//我们需要一个灰度图像来进行识别,所以我们
//创建与原始图像大小相同的新图像。
IplImage grayImage=IplImage.create(originalImage.width()、originalImage.height()、IPL_DEPTH_8U,1);
//我们将原始图像转换为灰度。
CVT颜色(原始图像、灰度图像、CV_BGR2GRAY);
CvMemStorage=CvMemStorage.create();
//我们使用级联定义实例化一个用于检测的分类器级联。
CvHaarClassifierCascade cascade=新的CvHaarClassifierCascade(cvLoad(cascade_文件));
//我们发现了这些面孔。
CvSeq faces=cvhaardetecobjects(灰度图像、级联、存储、1.1、1、0);
//我们在发现的面上迭代,并在其周围绘制黄色矩形。
对于(int i=0;i

我只是不知道问题出在哪里请帮助我快速搜索并找到了这个。尽管格式不同,但错误看起来是相同的

显然,除了java绑定之外,还必须安装核心OpenCV软件和库

希望