Firebase ML Kit how to run Face Detection in Background as service?

回眸只為那壹抹淺笑 提交于 2019-12-13 04:17:07

问题


In my app before i have used google gms vision for face detection . I have used the https://developers.google.com/android/reference/com/google/android/gms/vision/CameraSource.Builder to create the camerasource in my background service class.

But in Firebase ML Kit no common package is added for camerasource builder and preview. Is there any possibilities to use CameraSourcePreview and CameraSource Builder in Background service class.

I have tired by adding the CameraSourcePreview layout at window manager in service class like below. But no luck , its not running as i excepted. I need to detect the face whenever my service starts without preview layout visible. In app background and foreground also i need to detect the facial features.

Below code i have used for showing camerapreview at service class

LayoutInflater  inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);

    View mView = inflater.inflate(R.layout.child_camerapreview, null);

    wm.addView(mView, params);

Xml Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
>
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true"
    >
    <co.demo.facekit.common.CameraSourcePreview
        android:id="@+id/childbgCameraPreview"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true">

        <co.demo.facekit.common.GraphicOverlay
            android:id="@+id/childbgFaceOverlay"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentBottom="true"/>
    </co.demo.facekit.common.CameraSourcePreview>

</RelativeLayout>

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00000000"
    />

来源:https://stackoverflow.com/questions/53682721/firebase-ml-kit-how-to-run-face-detection-in-background-as-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!