FaceDetector icon indicating copy to clipboard operation
FaceDetector copied to clipboard

Incompatibility with Fotoapparat 2.1.2

Open victor5171 opened this issue 8 years ago • 8 comments

Hi!

I'm trying to couple FaceDetector to Fotoapparat but it looks like the newest version of it is incompatible with FaceDetector.

The following code is used to startup the camera and the detector:

val faceDetectorProcessor = FaceDetectorProcessor.with(this).listener { rectanglesView.setRectangles(it) }.build()

fotoApparat = Fotoapparat.with(this) .into(cameraView) .frameProcessor { faceDetectorProcessor.processFrame(it) } .build()

As you can see, the FrameProcessor property is now a lambda, so i've adapted the call.

But i'm receiving the following error (the application is crashing) if i run this code:

E/AndroidRuntime: FATAL EXCEPTION: pool-10-thread-1 Process: br.com.esapiens.ysos, PID: 17567 java.lang.IllegalAccessError: Field 'io.fotoapparat.preview.Frame.image' is inaccessible to class 'io.fotoapparat.facedetector.processor.FaceDetectorProcessor' (declaration of 'io.fotoapparat.facedetector.processor.FaceDetectorProcessor' appears in /data/app/br.com.esapiens.ysos-1/split_lib_dependencies_apk.apk) at io.fotoapparat.facedetector.processor.FaceDetectorProcessor.processFrame(FaceDetectorProcessor.java:37) at br.com.esapiens.ysos.camera.CameraActivity$onCreate$1.invoke(CameraActivity.kt:27) at br.com.esapiens.ysos.camera.CameraActivity$onCreate$1.invoke(CameraActivity.kt:11) at io.fotoapparat.preview.PreviewStream.dispatchFrame(PreviewStream.kt:92) at io.fotoapparat.preview.PreviewStream.access$dispatchFrame(PreviewStream.kt:14) at io.fotoapparat.preview.PreviewStream$dispatchFrameOnBackgroundThread$1.run(PreviewStream.kt:77) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at java.lang.Thread.run(Thread.java:818)

victor5171 avatar Jan 19 '18 10:01 victor5171

Thanks @victor5171. Let's think if @dmitry-zaitsev if we want the 2 libraries version independent or coupled.

Diolor avatar Jan 19 '18 11:01 Diolor

any solution for this problem?

ghost avatar Jan 29 '18 09:01 ghost

Can you please try FA 2.2.0? Curious why image field is not accessible.

Diolor avatar Feb 02 '18 11:02 Diolor

Hi!

I'm having the same problem as @victor5171 with FA 2.2.0 and FD 1.0.0. Any idea about a solution @Diolor ?

predasorinionut avatar Feb 06 '18 08:02 predasorinionut

This is the exception I get : FATAL EXCEPTION: pool-4-thread-1 java.lang.AbstractMethodError: abstract method "void io.fotoapparat.preview.FrameProcessor.process(io.fotoapparat.preview.Frame)" at io.fotoapparat.FotoapparatBuilder$frameProcessor$$inlined$apply$lambda$1.invoke(FotoapparatBuilder.kt:125) at io.fotoapparat.FotoapparatBuilder$frameProcessor$$inlined$apply$lambda$1.invoke(FotoapparatBuilder.kt:19) at io.fotoapparat.preview.PreviewStream.dispatchFrame(PreviewStream.kt:107) at io.fotoapparat.preview.PreviewStream.access$dispatchFrame(PreviewStream.kt:16) at io.fotoapparat.preview.PreviewStream$dispatchFrameOnBackgroundThread$1.run(PreviewStream.kt:92) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:762)f

ghost avatar Feb 08 '18 23:02 ghost

Hey @kim24 . I do get the same exception. Any heads up on it?

RationalRank avatar Mar 04 '18 09:03 RationalRank

I have a solution in the mean time, write your frame processor like this

frameProcessor = { val faces = faceDetector.detectFaces(it.image, it.size.width, it.size.height, it.rotation)
                                runOnUiThread {
                                    rectangles?.setRectangles(faces)
                                }
                            })

where faceDetector is

val faceDetector = FaceDetector.create(this)

In this way you essentially recreate FaceDetectorProcessor as a lambda function.

joelhaasnoot avatar Mar 06 '18 14:03 joelhaasnoot

Following @joelhaasnoot advice, here it is the Java version:

private class CustomFrameProcessor implements FrameProcessor {
    @Override
    public void process(@NotNull Frame frame) {

        List<Rectangle> faces = faceDetector.detectFaces(frame.getImage(), frame.getSize().width, frame.getSize().height, frame.getRotation());
        runOnUiThread(() -> rectanglesView.setRectangles(faces));
    }
}

FaceDetector faceDetector = FaceDetector.create(this);
CustomFrameProcessor processor = new CustomFrameProcessor();

fotoapparat = Fotoapparat.with(this)
			.frameProcessor(processor)
			...

scognito avatar Jan 03 '19 17:01 scognito