B4A Library Face detection with Google Mobile Vision API

The attached project (partially) wraps this Github project. In order to set it up you must follow this post (https://www.b4x.com/android/forum/threads/android-vision-barcode-reader-scan-qr-codes-and-other-1d-2d-barcodes.66408/) BUT use the attached B4A library files and B4A sample project:


You will initially need an internet connection as some "downloading" needs to take place before the face detection artefacts becomes visible. Note that it will not show immediately when you start the project - give it a minute or so after you have started the project and the detector artefacts will start showing.

Set the paths to the below correctly (inside the B4A project) to reflect your setup:
B4X:
#AdditionalRes: C:\Users\----------2\Documents\Basic 4 Android\JOHAN APPS\JHS LIBS\resource\b4a_appcompat, de.amberhome.objects.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\v7\appcompat\res, android.support.v7.appcompat
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
#AdditionalRes: C:\ANDRIOD_SDK_TOOLS\extras\android\support\design\res, android.support.design

Also posting the java code as it stands at present. Change it to your liking...

You can also try the Google Mobile Vision API barcode scanner that I have posted HERE

You can download and test it but if you want to use it then you need to

1.png



2.png



NOTE THE DETECTED HAPPINESS INDEX....:)
3.png
 

Attachments

  • TheJavaCode.zip
    42.4 KB · Views: 811
  • AndroidVisionFaceTrackerLibFiles.zip
    17.5 KB · Views: 948
  • b4aAndroidVisionFaceTracker.zip
    34.8 KB · Views: 998
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
The
#AdditionalRes: ..\resource
will not find this folder. It is missing in the example-zip
See post#1 for the setup and the link to the barcode posting. This project uses the same \resource folder and can be downloaded from the barcode posting....;)
 

Johan Schoeman

Expert
Licensed User
Longtime User
The
#AdditionalRes: ..\resource
will not find this folder. It is missing in the example-zip
OK - I have zipped the complete folder that I have been working with. It includes:
1. The Java Code
2. The B4A project
3. All the required library files
4. The source folder that needs to be in the B4A project (it should now be there by default)

The only other folder that is required is the attached folder than needs to be copied to the root of your additional library folder.

You can download the complete zipped project from here: https://www.dropbox.com/s/2btbfl3dgakgu7x/FaceTracker.zip?dl=0
 

Attachments

  • resourceInAddLibFolder.zip
    775 bytes · Views: 647

Reids

Member
Licensed User
Longtime User
I can compile the project, But after click the "Start Scan" suddenly apps is crashed "Unfortunately AndroidVisionFace has stopped"
I using Cyanogenmod 11, Kitkat 4.4.4, Gapps Installed too

PS : I using OLD Library of android-support-design.jar & android-support-v7-appcompat.jar also android-support-v4.jar AND compile with android-23 API
if I using your LIB file to my project, I couldn't even can see "Start Scan" screen, crashed on the first open

Here the log file
B4X:
LogCat connected to: 192.168.0.101:5555
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
ID of Front Facing Camera = 1
ID of Back Facing Camera = 0
Device has a flash = true
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main_scanner) Create, isFirst = true **
** Activity (main_scanner) Resume **
** Activity (main_scanner) Pause, UserClosed = false **
java.lang.RuntimeException: Unable to resume activity {JHS.AndroidVisionFaceTracker/main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 8487000 but found 8115000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2812)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2841)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5146)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 8487000 but found 8115000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    at com.google.android.gms.common.zze.zzan(Unknown Source)
    at com.google.android.gms.common.zze.isGooglePlayServicesAvailable(Unknown Source)
    at com.google.android.gms.common.zzc.isGooglePlayServicesAvailable(Unknown Source)
    at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source)
    at main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity.startCameraSource(FaceTrackerActivity.java:244)
    at main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity.onResume(FaceTrackerActivity.java:161)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
    at android.app.Activity.performResume(Activity.java:5310)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2802)
    ... 12 more
 

Johan Schoeman

Expert
Licensed User
Longtime User
I can compile the project, But after click the "Start Scan" suddenly apps is crashed "Unfortunately AndroidVisionFace has stopped"
I using Cyanogenmod 11, Kitkat 4.4.4, Gapps Installed too

PS : I using OLD Library of android-support-design.jar & android-support-v7-appcompat.jar also android-support-v4.jar AND compile with android-23 API
if I using your LIB file to my project, I couldn't even can see "Start Scan" screen, crashed on the first open

Here the log file
B4X:
LogCat connected to: 192.168.0.101:5555
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
ID of Front Facing Camera = 1
ID of Back Facing Camera = 0
Device has a flash = true
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main_scanner) Create, isFirst = true **
** Activity (main_scanner) Resume **
** Activity (main_scanner) Pause, UserClosed = false **
java.lang.RuntimeException: Unable to resume activity {JHS.AndroidVisionFaceTracker/main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 8487000 but found 8115000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2812)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2841)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5146)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 8487000 but found 8115000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    at com.google.android.gms.common.zze.zzan(Unknown Source)
    at com.google.android.gms.common.zze.isGooglePlayServicesAvailable(Unknown Source)
    at com.google.android.gms.common.zzc.isGooglePlayServicesAvailable(Unknown Source)
    at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source)
    at main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity.startCameraSource(FaceTrackerActivity.java:244)
    at main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity.onResume(FaceTrackerActivity.java:161)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
    at android.app.Activity.performResume(Activity.java:5310)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2802)
    ... 12 more
The pic below is from my Samsung GT-P3100 with Android 4.0.4 (the pics in the post above (post #1) were taken from my Samsung S4 mini with KitKat).

4.png


Seems as if your problem is here:

B4X:
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 8487000 but found 8115000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />

Do you have the most recent Google Play Services installed?
 
Last edited:

Reids

Member
Licensed User
Longtime User
Yeahhh I notice the error message too, "Expected 8487000 but found 8115000" Just updated Googleplay Service to rev 29 and now working great!
Thanks! this is really great libs!
 

Johan Schoeman

Expert
Licensed User
Longtime User
I can compile the project, But after click the "Start Scan" suddenly apps is crashed "Unfortunately AndroidVisionFace has stopped"
I using Cyanogenmod 11, Kitkat 4.4.4, Gapps Installed too

PS : I using OLD Library of android-support-design.jar & android-support-v7-appcompat.jar also android-support-v4.jar AND compile with android-23 API
if I using your LIB file to my project, I couldn't even can see "Start Scan" screen, crashed on the first open

Here the log file
B4X:
LogCat connected to: 192.168.0.101:5555
--------- beginning of /dev/log/main
--------- beginning of /dev/log/system
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
ID of Front Facing Camera = 1
ID of Back Facing Camera = 0
Device has a flash = true
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (main_scanner) Create, isFirst = true **
** Activity (main_scanner) Resume **
** Activity (main_scanner) Pause, UserClosed = false **
java.lang.RuntimeException: Unable to resume activity {JHS.AndroidVisionFaceTracker/main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity}: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 8487000 but found 8115000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2812)
    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2841)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276)
    at android.app.ActivityThread.access$800(ActivityThread.java:144)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5146)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value.  Expected 8487000 but found 8115000.  You must have the following declaration within the <application> element:     <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
    at com.google.android.gms.common.zze.zzan(Unknown Source)
    at com.google.android.gms.common.zze.isGooglePlayServicesAvailable(Unknown Source)
    at com.google.android.gms.common.zzc.isGooglePlayServicesAvailable(Unknown Source)
    at com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source)
    at main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity.startCameraSource(FaceTrackerActivity.java:244)
    at main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity.onResume(FaceTrackerActivity.java:161)
    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)
    at android.app.Activity.performResume(Activity.java:5310)
    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2802)
    ... 12 more

How about this and the displayed happiness index.....:D

b4a3.png
 

Reids

Member
Licensed User
Longtime User
Yeah I notice it too about happines index that was great!
But some feature not fully worked yet :
-After capture Id of scan not logged maybe because "scanner_scan_result" event not triggered

Can you implement feature to detect (compare) the similiary of sample image with the captured image?
compare face in stored image file (jpg file) with captured (camera live photo) of image
 

Johan Schoeman

Expert
Licensed User
Longtime User
Yeah I notice it too about happines index that was great!
But some feature not fully worked yet :
-After capture Id of scan not logged maybe because "scanner_scan_result" event not triggered

Can you implement feature to detect (compare) the similiary of sample image with the captured image?
compare face in stored image file (jpg file) with captured (camera live photo) of image
The Google Mobile Vision API is not a face recognition/identification system. It is purely a face detection system. Thus, at this stage it seems to have very limited application other that telling you how HAPPY the person(s) in the camera's preview is....
 
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
Does this lib need internet to work? Sorry for my silly question, I'm on mobile so can't test your lib. Thank you.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Does this lib need internet to work? Sorry for my silly question, I'm on mobile so can't test your lib. Thank you.
Only initially when first installed. See post #1
 

DonManfred

Expert
Licensed User
Longtime User
Does this lib need internet to work?
You will initially need an internet connection as some "downloading" needs to take place before the face detection artefacts becomes visible. Note that it will not show immediately when you start the project - give it a minute or so after you have started the project and the detector artefacts will start showing.
 

Douglas Farias

Expert
Licensed User
Longtime User
hi @Johan Schoeman
i tested your samples and lib.

here on my device the camera works fine, but this dont find face.

i only see a pink start scan button, the camera opens and later dont detect faces like your images and dont show any logs.

My device is the Samsung Galaxy J2 - Android 5.1

Can is the focus? this example dont work the focus

PS: already added
B4X:
AddPermission(android.permission.INTERNET)
AddPermission (android.permission.ACCESS_NETWORK_STATE)
- I have internet connection
- Already tryed wait 2 Min + and no detection
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
hi @Johan Schoeman
i tested your samples and lib.

here on my device the camera works fine, but this dont find face.

i only see a pink start scan button, the camera opens and later dont detect faces like your images and dont show any logs.

My device is the Samsung Galaxy J2 - Android 5.1

Can is the focus? this example dont work the focus

PS: already added
B4X:
AddPermission(android.permission.INTERNET)
AddPermission (android.permission.ACCESS_NETWORK_STATE)
- I have internet connection
- Already tryed wait 2 Min + and no detection
The manifest in the project that I have posted:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="22"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
SetApplicationAttribute(android:theme, "@style/MyAppTheme")
AddApplicationText(<meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
        <meta-data
            android:name="com.google.android.gms.vision.DEPENDENCIES"
            android:value="face" />
        <activity android:name="main.java.com.google.android.gms.samples.vision.face.facetracker.FaceTrackerActivity"
            android:screenOrientation="portrait" android:configChanges="orientation|keyboardHidden">
        </activity>)   
AddPermission(android.permission.CAMERA) ' Required to be able to access the camera device.       
AddPermission(android.permission.GET_TASKS)
AddPermission("android.hardware.camera")
AddPermission("android.permission.FLASHLIGHT")

Is that what you have in your project?
 
Top