Im trying to create a camera app with FaceRecognition from an image. So I implement an native Android Camera, a button and an ClickListener. So when I touch that button I generate an image and after that I need check if has any face. And this what Im doing.
So I follow all the Tutorials from OpenCvAndroid Tuts
If I run without any OpenCV methods or calls my app works fine.
here is my onCreate Method who get a camera instance:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Boolean hasCamera = checkCameraHardware(getApplicationContext());
if(!hasCamera){
Toast.makeText(getApplicationContext(), "Camera Not Available", Toast.LENGTH_LONG).show();
}else{
// Create an instance of Camera
mCamera = getCameraInstance();
// Create our Preview view and set it as the content of our activity.
mPreview = new CameraPreview(this, mCamera);
RelativeLayout preview = (RelativeLayout) findViewById(R.id.camera_preview);
preview.addView(mPreview);
mSnapButton = (ImageButton) findViewById(R.id.button_capture);
mSnapButton.bringToFront();
// capture image button
mSnapButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// get an image from the camera
mCamera.takePicture(null, null, mPicture);
}
});
}
}
getCameraInstance()
private Camera getCameraInstance() {
Camera c = null;
try {
Log.e(" PELUCHE ", " No de Cameras--> "+ c.getNumberOfCameras());
c = Camera.open(c.getNumberOfCameras() - 1 ); // attempt to get a Camera instance
} catch (Exception e) {
// Camera is not available (in use or does not exist)
}
return c; // returns null if camera is unavailable
}
SaveImage on SDCARD and after that check with OpenCV
private PictureCallback mPicture = new PictureCallback() {
@Override
public void onPictureTaken(byte[] data, Camera camera) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null) {
Log.d(TAG,
"Error creating media file, check storage permissions");
return;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
fos.write(data);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
}
mCamera.startPreview();
// call alert dialog to display file saved location
alertDialog("Imagen Guardada",
"Image saved in: " + DIRECTORY_SAVE_IMAGES + " SDCARD");
Log.e("PeluChe", "FileName -> " + pictureFile.getName() );
/*
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
Mat image = Highgui.imread(FaceDetector.class.getResource(pictureFile.getName()).getPath());
CascadeClassifier faceDetector = new CascadeClassifier(FaceDetector.class.getResource("haarcascade_frontalface_alt.xml").getPath());
Mat image = Highgui.imread(FaceDetector.class.getResource(pictureFile.getName()).getPath());
MatOfRect faceDetections = new MatOfRect();
faceDetector.detectMultiScale(image,faceDetections);
Log.e("PeluChe", "Detect FACES -> " + faceDetections.toArray().length);
*/
}
};
So If I uncomment the:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
I get:
java.lang.UnsatisfiedLinkError: Couldn't load opencv_java249: findLibrary returned null
I follow How setup for opencv java jar library .