Hello guys, I've developed an app utilizing face detection function of android OS on 4.0.4. Basic function is detecting a single face and drawing a rectangle around the detected face. (yes, very typical and easy) I've upgrade the OS to 4.1.2 then the rectangle does not appear in spite face detection works well. Environment: 1. Ubuntu 12.04 LTS 2. Android 4.1.2 3. latest android phones: optimus G, galaxy note 2 etc. Symptoms: 0. on 4.0.4, everything is fine. 1. on 4.1.2, A. without face detection, drawRect with STROKE paint works nornally. B. with face detection, drawRect with STROKE does not works. No rectangle draws. C. with face detection, drawRect with FILL works well, but you know, rectangle hides a face. D. with face detection, drawRect with STROKE set some styles (dashed, rounded corner ..) does abnormally: draws a part of a rectangle occasionally. These are bothering me. Please help me. Thank you. Here is my test code:
> public class MainActivity extends Activity { > > Preview mPreview; > DrawOnTop mDraw; > > @Override > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > > requestWindowFeature(Window.FEATURE_NO_TITLE); > > mPreview = new Preview(this); > mDraw = new DrawOnTop(this); > > setContentView(mPreview); > addContentView(mDraw, new LayoutParams(LayoutParams.WRAP_CONTENT, > LayoutParams.WRAP_CONTENT)); > } > > > class DrawOnTop extends View { > public DrawOnTop(Context context) { > super(context); > } > > Rect face = new Rect(); > > public void setFace(Rect r) { > face = r; > invalidate(); > } > @Override > protected void onDraw(Canvas canvas) { > Paint paint = new Paint(); > paint.setStyle(Paint.Style.*STROKE*); > paint.setColor(Color.RED); > paint.setStrokeWidth(10); > canvas.drawRect(face, paint); > > super.onDraw(canvas); > } > } > > > class Preview extends SurfaceView implements SurfaceHolder.Callback { > SurfaceHolder mHolder; > Camera mCamera; > > int width; > int height; > > Preview(Context context) { > super(context); > mHolder = getHolder(); > mHolder.addCallback(this); > } > > public void surfaceCreated(SurfaceHolder holder) { > mCamera = Camera.open(0); > mCamera.setPreviewDisplay(holder); > } > > public void surfaceDestroyed(SurfaceHolder holder) { > mCamera.stopPreview(); > mCamera.release(); > mCamera = null; > } > > public void surfaceChanged(SurfaceHolder holder, int format, int w, > int h) { > > width = w; > height = h; > Camera.Parameters parameters = mCamera.getParameters(); > parameters.setPreviewSize(w, h); > mCamera.setParameters(parameters); > mCamera.setFaceDetectionListener(mFaceDetectionListener); > mCamera.startPreview(); > mCamera.startFaceDetection(); > } > > Camera.FaceDetectionListener mFaceDetectionListener = new > Camera.FaceDetectionListener() { > @Override > public void onFaceDetection(Face[] arg0, Camera arg1) { > if(arg0.length > 0) { > Rect r = arg0[0].rect; > Rect res = new Rect(); > res.top = height/2 + height*r.top/2000; > res.bottom = height/2 + height*r.bottom/2000; > res.left = width/2 - width*r.left/2000; > res.right = width/2 - width*r.right/2000; > > Log.v("Face", String.format("%d, %d, %d, %d", res.top, res.left, > res.bottom, res.right)); > > mDraw.setFace(res); > } > } > }; > } > } > -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.