This github link - https://github.com/microsoft/Cognitive-Face-Android
return faceServiceClient.detect() this line code not working in android 11
private class DetectionTask extends AsyncTask<InputStream, String, Face[]> {
@Override
protected Face[] doInBackground(InputStream... params) {
// Get an instance of face service client to detect faces in image.
FaceServiceClient faceServiceClient = SampleApp.getFaceServiceClient();
try {
publishProgress("Detecting...");
// Start detection.
- return faceServiceClient.detect(
- params[0], /* Input stream of image to detect */
- true, /* Whether to return face ID */
- false, /* Whether to return face landmarks */
- /* Which face attributes to analyze, currently we support:
- age,gender,headPose,smile,facialHair */
- null);
// setUiBeforeBackgroundTask();} catch (Exception e) { publishProgress(e.getMessage()); return null; } } @Override protected void onPreExecute() {
}
// // Set the adapter of the ListView which contains the details of detected faces.@Override protected void onProgressUpdate(String... values) { // Show the status of background detection task on screen. setUiDuringBackgroundTask(values[0]); } @Override protected void onPostExecute(Face[] result) { progressDialog.dismiss(); if (result != null) {
mFaceListAdapter = new FaceListAdapter(result);
ListView listView = (ListView) findViewById(R.id.list_identified_faces);
listView.setAdapter(mFaceListAdapter);
*/if (result.length == 0) { try { detected = false; setInfo("No faces detected!"); AlertDialog.Builder builder = new AlertDialog.Builder(PunchinActivity.this, R.style.AppCompatAlertDialogStyleErrorUpdate); builder.setTitle(getResources().getString(R.string.app_name)); builder.setMessage("No faces detected!"); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { myAlertDialog.dismiss(); FaceListAdapter faceListAdapter = new FaceListAdapter(null); /* ListView listView = (ListView) findViewById(R.id.list_identified_faces); listView.setAdapter(faceListAdapter); setInfo(""); myCamera.startPreview();
try { myCamera.stopPreview(); myCamera.release(); myCamera = null; } catch (Exception e) { e.printStackTrace(); } finish(); } }); builder.setCancelable(false); myAlertDialog = builder.create(); myAlertDialog.show(); } catch (Resources.NotFoundException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } else { detected = true; setInfo("Click on the \"Identify\" button to identify the faces in image."); identify(); } } else { detected = false; }
// refreshIdentifyButtonEnabledStatus();
}
}