栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Android人脸检测

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Android人脸检测

为此,工作并从给定图片中检测所有面孔

    public class AndroidFaceDetector extends Activity {        @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        //setContentView(R.layout.main);        setContentView(new myView(this));    }    private class myView extends View{     private int imageWidth, imageHeight;     private int numberOfFace = 5;     private FaceDetector myFaceDetect;      private FaceDetector.Face[] myFace;     float myEyesDistance;     int numberOfFaceDetected;     Bitmap myBitmap;    public myView(Context context) {   super(context);   // TODO Auto-generated constructor stub   BitmapFactory.Options BitmapFactoryOptionsbfo = new BitmapFactory.Options();   BitmapFactoryOptionsbfo.inPreferredConfig = Bitmap.Config.RGB_565;    myBitmap = BitmapFactory.depreResource(getResources(), R.drawable.face5,         BitmapFactoryOptionsbfo);   imageWidth = myBitmap.getWidth();   imageHeight = myBitmap.getHeight();   myFace = new FaceDetector.Face[numberOfFace];   myFaceDetect = new FaceDetector(imageWidth, imageHeight, numberOfFace);   numberOfFaceDetected = myFaceDetect.findFaces(myBitmap, myFace);  }  @Override  protected void onDraw(Canvas canvas) {   // TODO Auto-generated method stub canvas.drawBitmap(myBitmap, 0, 0, null); Paint myPaint = new Paint(); myPaint.setColor(Color.GREEN); myPaint.setStyle(Paint.Style.STROKE);  myPaint.setStrokeWidth(3); for(int i=0; i < numberOfFaceDetected; i++) {  Face face = myFace[i];  PointF myMidPoint = new PointF();  face.getMidPoint(myMidPoint);    myEyesDistance = face.eyesDistance();  canvas.drawRect(    (int)(myMidPoint.x - myEyesDistance),    (int)(myMidPoint.y - myEyesDistance),    (int)(myMidPoint.x + myEyesDistance),    (int)(myMidPoint.y + myEyesDistance),    myPaint); }  }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/440453.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号