October 4th, 2012, 08:15 AM
|
#1 (permalink)
|
|
New Member
Thread Author (OP)
Join Date: Aug 2012
Posts: 2
Device(s):
Carrier: Not Provided
Thanks: 0
Thanked 0 Times in 0 Posts
|
Face detection problem
Hi,
im using a samsung galaxy S2 i9100 to develope a simple face detection app, here is my code:
import android.media.FaceDetector;
import android.media.FaceDetector.Face;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class DigitalEye extends Activity implements View.OnClickListener {
Button TakePic,faceButton;
ImageView Photo;
TextView Caras;
Intent camara;
final static int camaraData = 0;
Bitmap bmpCamara;
ImageView Caraprueba;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_digital_eye);
TakePic = (Button) findViewById(R.id.takepic);
faceButton = (Button) findViewById(R.id.face);
Caras = (TextView) findViewById(R.id.Caras);
Photo = (ImageView) findViewById(R.id.photo);
Caraprueba = (ImageView) findViewById(R.id.caraprueba);
TakePic.setOnClickListener(this);
faceButton.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_digital_ eye, menu);
return true;
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.takepic:
camara = new Intent(android.provider.MediaStore.ACTION_IMAGE_CA PTURE);
startActivityForResult(camara, camaraData);
break;
case R.id.face:
Bitmap bmpface = bmpCamara;
int width = bmpface.getWidth();
int heigth = bmpface.getHeight();
Face[] Face = new FaceDetector.Face[5];
FaceDetector Detector = new FaceDetector(width,heigth,5);
Bitmap bitmap565 = Bitmap.createBitmap(width, heigth, Config.RGB_565);
Paint ditherPaint = new Paint();
Paint drawPaint = new Paint();
ditherPaint.setDither(true);
drawPaint.setColor(Color.RED);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeWidth(2);
Canvas canvas = new Canvas();
canvas.setBitmap(bitmap565);
canvas.drawBitmap(bmpface, 0, 0, ditherPaint);
int Num_Face = Detector.findFaces(bitmap565, Face);
Caras.setText("Caras reconocidas:----> " + Num_Face);
Caraprueba.setImageBitmap(bmpface);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
Bundle extras = data.getExtras();
bmpCamara = (Bitmap) extras.get("data");
Photo.setImageBitmap(bmpCamara);
}
}
}
i have a button to take the picture and another one to do the face detection, the problem is it only works when i use the front camera!, i cant make it work with the back camera and i dont know why. i would like a little help here :P, thanks
|
|
|