Skip to content

Camera view is black, no video preview and no faces are detected #44

@Zaniyar

Description

@Zaniyar

I am using FotoApparat in my App.
When I try to implement the facedetector the Camera View stays black. Nothing to see.

app/build.gradle:

    implementation 'io.fotoapparat:facedetector:1.0.0'
    implementation 'io.fotoapparat:fotoapparat:2.7.0'

MainActivity.kt:


    override fun onCreate(savedInstanceState: Bundle?) {
            ...
        createFotoapparat()
           ...
     }

    private fun createFotoapparat(){
        val cameraView = findViewById<CameraView>(R.id.cameraView)
        fotoapparat = Fotoapparat(
            context = this,
            view = cameraView,
            scaleType = ScaleType.CenterCrop,
            lensPosition = back(),
            logger = loggers(
                logcat()
            ),
            cameraErrorCallback = { error ->
                println("Recorder errors: $error")
            }
        ) 
        // now the processor - when I delete this and also the layouts in the view, Camera preview is visible again
        val processor = FaceDetectorProcessor.with(this)
            .listener({ faces ->
                rectanglesView.setRectangles(faces)  // (Optional) Show detected faces on the view.
                Log.v("Faces",faces.toString());   // is never called!
                // ... or do whatever you want with the result
            })
            .build()

        Fotoapparat.with(this)
            .into(cameraView)
            // the rest of configuration
            .frameProcessor(processor)
            .build()

    }

activity_main.xml:


    <io.fotoapparat.facedetector.view.CameraOverlayLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <!-- Adjust parameters as you like. But cameraView has to be inside CameraOverlayLayout -->
        <io.fotoapparat.view.CameraView
                android:id="@+id/cameraView"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

        <!-- This view will display detected faces -->
        <io.fotoapparat.facedetector.view.RectanglesView
                android:id="@+id/rectanglesView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:rectanglesColor="@color/colorAccent"
                app:rectanglesStrokeWidth="2dp"/>

    </io.fotoapparat.facedetector.view.CameraOverlayLayout>

I don't get any errors, but I don't see anything. No faces, no camera preview stream.

...

When I add this line, I get the error (I am not sure if this is needed, when I already io.fotoapparat:fotoapparat:2.7.0) :

ERROR: Failed to resolve: io.fotoapparat.fotoapparat:library:1.0.0

for:

    // If you are using Fotoapparat add this one as well
    implementation 'io.fotoapparat.fotoapparat:library:1.2.0' // or later version 

Any ideas?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions