我在我的应用程序中使用Mobile Vision API进行人脸检测到目前为止我已经成功完成了这项工作。 它适用于我第一次运行应用程序时设置的特定图像,但之后...我试图替换不同的图像进行面部检测,它给出了错误java.lang.OutOfMemoryError
以下是我的代码
SELECT CONVERT(Datetime, '2015-10-29 15:01:00', 120)
这是我的logcat
Bitmap myBitmap;
FaceDetector detector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Load An Image////
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable=true;
Bitmap b = = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.image,options);
myBitmap = b.copy(Bitmap.Config.RGB_565, true);
b.recycle();
////////////////
detector = new FaceDetector.Builder(getApplicationContext())
.setTrackingEnabled(false)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.build();
if (!detector.isOperational())
{ Toast.makeText(MainActivity.this, "NO face deteted."Toast.LENGTH_SHORT)
.show();}
else {
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<com.google.android.gms.vision.face.Face> faces = detector.detect(frame);
FaceView faceView = (FaceView) findViewById(R.id.faceView);
faceView.setContent(myBitmap, faces);
}
......需要你的帮助......
答案 0 :(得分:0)
试试这个
Bitmap myBitmap;
FaceDetector detector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Load An Image////
BitmapFactory.Options options = new BitmapFactory.Options();
options.inMutable=true;
Bitmap b = = BitmapFactory.decodeResource(
getApplicationContext().getResources(),
R.drawable.image,options);
myBitmap = b.copy(Bitmap.Config.RGB_565, true);
b.recycle();
//////////////////
detector = new FaceDetector.Builder(getApplicationContext())
.setTrackingEnabled(false)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.build();
Detector<Face> safeDetector = new SafeFaceDetector(detector);
Frame frame = new Frame.Builder().setBitmap(myBitmap).build();
SparseArray<com.google.android.gms.vision.face.Face> faces = safeDetector.detect(frame);
if (!safeDetector.isOperational()) {
Toast.makeText(MainActivity.this, "NO face deteted."Toast.LENGTH_SHORT)
.show();
} else {
FaceView faceView = (FaceView) findViewById(R.id.faceView);
faceView.setContent(myBitmap, faces);
safeDetector.release();
}
}
for use facedetector release();
必须在使用后调用。
和SafeDetector
用法:面部检测器有小图像的bug,而safeDetector是该bug的补丁
在活动导入
添加此行import com.google.android.gms.samples.vision.face.patch.SafeFaceDetector;