Android Question Help me with Face++ API Face recognition

mike1967

Active Member
Licensed User
Longtime User
hello i'm try to use Face++ api for face detect and recognition with b4a with the following code:

#Region Project Attributes
#ApplicationLabel: MyFace
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
Dim hc As HttpJob
Dim ApiUrl, ApiKey,ApiSecret As String

End Sub

Sub globals
End Sub

Sub Activity_Create(FirstTime As Boolean)
ApiKey = ""
ApiSecret = ""
ApiUrl = "http://apius.faceplusplus.com/v2/detection/detect"
' https://apius.faceplusplus.com/v2/detection/detect
' ?api_secret=XXXXXX&api_key=XXXXXX&attribute=gender,age&img[POST]=1.jpg

If FirstTime Then
hc.initialize("hc",Me)

End If
Activity.LoadLayout("main")

hc.Poststring(ApiUrl,"&api_key="&ApiKey&"&api_secret="&ApiSecret&"&url="&File.Combine(File.DirRootExternal,"1.jpg"))

End Sub

Sub jobdone(Job As HttpJob)
Dim res As String
Dim parser As JSONParser

If Job.Success=True Then
res = Job.GetString
Log("Response from server: " & res)
Else

End If
Job.Release

End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


the job.success never fire

were i wrong ?
Thanks
 

mike1967

Active Member
Licensed User
Longtime User
Please use [code]code here...[/code] tags when posting code.


Put a breakpoint in JobDone. Maybe it is raised with Job.Success set to False.

In effect the job was unsuccesful cause file not found.

How i can upload the file 1.jpg with
B4X:
hc.Poststring(ApiUrl,"&api_key="&ApiKey&"&api_secret="&ApiSecret&"&url="&File.Combine(File.DirRootExternal,"1.jpg"))

Thanks
 
Upvote 0

jchal

Active Member
Licensed User
Longtime User
it looked intresting i try to run it just to get an idea but....... this is what i got, why?
Logger connected to: samsung GT-I9060
--------- beginning of /dev/log/main
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 35 (Main)
java.io.FileNotFoundException: /storage/emulated/0/Android/data/b4a.example/files/virtual_assets/main.bal: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:416)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:199)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:78)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at b4a.example.main._activity_create(main.java:396)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:400)
... 25 more
** Activity (main) Resume **
** Service (starter) Create **
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 35 (Main)
java.io.FileNotFoundException: /storage/emulated/0/Android/data/b4a.example/files/virtual_assets/main.bal: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:416)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at anywheresoftware.b4a.objects.streams.File.OpenInput(File.java:199)
at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:78)
at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
at b4a.example.main._activity_create(main.java:396)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at b4a.example.main.afterFirstLayout(main.java:102)
at b4a.example.main.access$000(main.java:17)
at b4a.example.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:5319)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:400)
... 25 more
** Activity (main) Resume **
 
Upvote 0
Top