1

我正在制作一个人脸检测应用程序(不是实时的)来检测 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]  

以下是我的代码:

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

}

我只是不知道是什么问题请帮忙

4

2 回答 2

0

问题似乎是链接opencv。您是否在路径变量中包含了 opencv\build\x64\vc10\bin ?也检查下面的链接。 https://code.google.com/p/javacv/wiki/Windows7AndOpenCV

于 2013-04-19T12:33:03.743 回答
0

快速搜索并想出了这个。即使格式不同,错误看起来也一样。

javaCV UnsatisfiedLinkError

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

希望这可以帮助

于 2012-06-23T23:30:39.947 回答