【问题标题】:Face Detection on images using JavaCV for Android使用 JavaCV for Android 对图像进行人脸检测
【发布时间】:2012-06-25 18:58:26
【问题描述】:

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

}

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

【问题讨论】:

    标签: android face-detection javacv


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      javaCV UnsatisfiedLinkError

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

      希望对你有帮助

      【讨论】:

      • 核心 OpenCV 库和软件已经安装(版本 2.3.1).....
      • 您的程序仍然可能找不到它们,您检查它们是否在它们所属的位置?它通常会导致不满意的链接错误
      • 我已经检查过了,但我会重新检查......或者它可能是版本的问题......:s
      • 可能......您使用的是什么版本的 JavaCV 绑定?如果它不是太麻烦,你可能应该更新到最新版本,2.3.1 看起来很旧(约 10 个月和 2 个版本)
      猜你喜欢
      • 2012-05-18
      • 1970-01-01
      • 2012-02-17
      • 1970-01-01
      • 1970-01-01
      • 2019-03-28
      • 2013-09-02
      • 2013-11-07
      • 1970-01-01
      相关资源
      最近更新 更多