2012-06-23 80 views
1

我正在製作一個人臉檢測應用程序(不是實時)來檢測圖像上的人臉android 我嘗試使用android.media中的FaceDetector類,這很好,但它不是'非常準確。 所以我下載JavaCV和java.cpp包 (與OpenCV的V 2.3) 該項目運行,但給人的例外:使用JavaCV for Android的圖像上的人臉檢測

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

} 

我只是不知道是什麼是問題請幫助

回答

0

做了一個快速搜索,想出了這個。即使格式不同,錯誤看起來也是一樣的。

javaCV UnsatisfiedLinkError

顯然,你必須有安裝在它除了Java綁定核心OpenCV的軟件和庫。

希望這會有幫助

+0

核心OpenCV庫和軟件已經安裝(版本2.3.1)..... –

+0

它仍然有可能你的程序找不到它們,你檢查他們是屬於哪裏嗎?通常它的一些變化,導致不滿意的鏈接錯誤 – pdel

+0

我已經檢查,但我會重新檢查它.....或者它的問題與版本.... s –