Firebase ML Kit how to run Face Detection in Backg

2019-08-21 18:25发布

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"
    />

0条回答
登录 后发表回答