android - Extraction Of Face From a Bitmap -
after being given suggestions use circular crop implemented in application use extract face bitmap inefficient mean of no use , similar cropping rectangular face. here have done til now:
- launched camera
- taken picture
- detected face in picture
- painting rectangular window in area face has been detected
now serious issue facing getting face bitmap. want face. ignore other details in face detection window. if matlab have been simpler of edge detection techniques , segmentation algorithms , function. want know how can same process in android application? plz share code snippets if u know of any. taking of time , want on face extraction part.
code did till now:
public class makeover extends activity { private static final int take_picture_code = 100; private static final int max_faces = 5; private bitmap camerabitmap = null; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); ((button)findviewbyid(r.id.take_picture)).setonclicklistener(btnclick); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if(take_picture_code == requestcode){ processcameraimage(data); } } private void opencamera(){ intent intent = new intent(android.provider.mediastore.action_image_capture); startactivityforresult(intent, take_picture_code); } private void processcameraimage(intent intent){ setcontentview(r.layout.detectlayout); ((button)findviewbyid(r.id.detect_face)).setonclicklistener(btnclick); imageview imageview = (imageview)findviewbyid(r.id.image_view); camerabitmap = (bitmap)intent.getextras().get("data"); imageview.setimagebitmap(camerabitmap); } private void detectfaces(){ bitmap bmface = null; if(null != camerabitmap){ int width = camerabitmap.getwidth(); int height = camerabitmap.getheight(); facedetector detector = new facedetector(width, height,makeover.max_faces); face[] faces = new face[makeover.max_faces]; bitmap bitmap565 = bitmap.createbitmap(width, height, config.rgb_565); paint ditherpaint = new paint(); paint drawpaint = new paint(); //jo bhi krna hai ab bitmap565 k sath krna hai apse wo image hai main ditherpaint.setdither(true); drawpaint.setcolor(color.red); drawpaint.setstyle(paint.style.stroke); drawpaint.setstrokewidth(2); canvas canvas = new canvas(); canvas.setbitmap(bitmap565); canvas.drawbitmap(camerabitmap, 0, 0, ditherpaint); int facesfound = detector.findfaces(bitmap565, faces); pointf midpoint = new pointf(); float eyedistance = 0.0f; float confidence = 0.0f; log.i("facedetector", "number of faces found: " + facesfound); if(facesfound > 0) { for(int index=0; index<facesfound; ++index){ faces[index].getmidpoint(midpoint); eyedistance = faces[index].eyesdistance(); confidence = faces[index].confidence(); log.i("facedetector", "confidence: " + confidence + ", eye distance: " + eyedistance + ", mid point: (" + midpoint.x + ", " + midpoint.y + ")"); canvas.drawrect((int)midpoint.x - eyedistance , (int)midpoint.y - eyedistance , (int)midpoint.x + eyedistance, (int)midpoint.y + eyedistance, drawpaint); } } for(int count=0;count<detector.findfaces(bitmap565, faces);count++) { float left; float top; pointf midpoints=new pointf(); faces[count].getmidpoint(midpoint); eyedistance=faces[count].eyesdistance(); left = midpoint.x - (float)(1.4 * eyedistance); top = midpoint.y - (float)(1.8 * eyedistance); bmface = bitmap.createbitmap(camerabitmap, (int) left, (int) top, (int) (2.8 * eyedistance), (int) (3.6 * eyedistance)); } string filepath = environment.getexternalstoragedirectory() + "/facedetect" + system.currenttimemillis() + ".jpg"; try { fileoutputstream fos = new fileoutputstream(filepath); bitmap565.compress(compressformat.jpeg, 90, fos); fos.flush(); fos.close(); } catch (filenotfoundexception e) { e.printstacktrace(); } catch (ioexception e) { e.printstacktrace(); } imageview imageview = (imageview)findviewbyid(r.id.image_view); imageview.setimagebitmap(bmface); } } private view.onclicklistener btnclick = new view.onclicklistener() { @override public void onclick(view v) { switch(v.getid()){ case r.id.take_picture: opencamera(); break; case r.id.detect_face: detectfaces(); break; } } }; }
Comments
Post a Comment