public class CrowdDetection extends Activity {ImageVIEw display;ImageVIEw pic;Bitmap image;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_crowd_detection); display = (ImageVIEw) findVIEwByID(R.ID.imageVIEw2); button takePicture = (button) findVIEwByID(R.ID.button1); takePicture.setonClickListener(new OnClickListener() { @OverrIDe public voID onClick(VIEw v) { Intent intent = new Intent(androID.provIDer.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent,0); } });}@OverrIDeprotected voID onActivityResult(int requestCode,int resultCode,Intent data){ super.onActivityResult(requestCode,resultCode,data); setContentVIEw(R.layout.detect_faces); pic = (ImageVIEw) findVIEwByID(R.ID.imageVIEw1); image = (Bitmap) data.getExtras().get("data"); image = BitmapFactory.decodefile(data.getData().getPath()); pic.setimageBitmap(image); button detect = (button) findVIEwByID(R.ID.button2); detect.setonClickListener(new OnClickListener(){ @OverrIDe public voID onClick(VIEw v){ detectFaces(); } }); }private voID detectFaces() { setContentVIEw(R.layout.display_crowd); int h = image.getHeight(); int w = image.getWIDth(); int max = 10; FaceDetector detector = new FaceDetector(w,h,max); Face[] faces = new Face[max]; ImageVIEw pic2 = (ImageVIEw) findVIEwByID(R.ID.imageVIEw3); pic2.setimageBitmap(image); int facesFound = detector.findFaces(image,faces); TextVIEw result = (TextVIEw) findVIEwByID(R.ID.textVIEw3); if(facesFound>5){ result.setText("There are " + facesFound + " faces in this picture,therefore you have a crowd!"); } else{ result.setText("There are only " + facesFound + " faces in this picture,therefore you do not have a crowd!"); }}@OverrIDepublic boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.crowd_detection,menu); return true;}}
我在这里先向您的帮助表示感谢!
解决方法 您无法检测任何面部的原因是您需要将位图转换为RGB 565.使用此选项可将位图转换为RGB 565
BitmapFactory.Options bitmapFatoryOptions=new BitmapFactory.Options();bitmapFatoryOptions.inPreferredConfig=Bitmap.Config.RGB_565;image=BitmapFactory.decodeResource(getResources(),R.drawable.image,bitmapFatoryOptions);总结
以上是内存溢出为你收集整理的Android FaceDetector找不到任何面孔… findFace()每次都返回0全部内容,希望文章能够帮你解决Android FaceDetector找不到任何面孔… findFace()每次都返回0所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)