How to integrate Huawei HMS Face Liveness Detection with CameraView? - face-detection

First, I tried Huawei Face Liveness Detection. With the sample code, it works.
Next, I tried CameraView. Also, by just following the sample code, I am able to perform frame processing, achieving face detection and face recognition.
<com.otaliastudios.cameraview.CameraView
app:cameraFacing="front"
android:id="#+id/cameraView"
app:cameraEngine="camera2"
app:cameraPreview="glSurface"
android:keepScreenOn="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible"
app:cameraAudio="off"
app:cameraExperimental="true">
</com.otaliastudios.cameraview.CameraView>
Question: How to integrate Huawei Face Liveness Detection into CameraView?
Provided the Face Liveness Detection code below, I tried changing the view container (mPreviewContainer as below), but it just throws error and app exits.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_liveness_custom_detection);
mPreviewContainer = findViewById(R.id.surface_layout); //<------ Change this to CameraView
mlLivenessDetectView = new MLLivenessDetectView.Builder()
.setContext(this)
.setFaceFrameRect(new Rect(0, 0, 0, 200))
.setDetectCallback(new OnMLLivenessDetectCallback() {
...
}
I am curious how to integrate the Huawei Face Liveness Detection into CameraView (or even normal Camera2 or CameraX)? Can the HMS take the input frames from CameraView, instead of opening another camera?
P.S.:
The first error appeared (out of the lengthy message):
I/BufferQueue: [unnamed-11129-0](this:0x70859fb800,id:0,api:0,p:-1,c:-1) BufferQueue core=(11129:com.example.cv1)
E/AndroidRuntime: FATAL EXCEPTION: CameraViewEngine
Process: com.example.cv1, PID: 11129
com.otaliastudios.cameraview.CameraException
at com.otaliastudios.cameraview.engine.Camera2Engine$2.onDisconnected(Camera2Engine.java:435)
at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:252)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:226)
at android.os.HandlerThread.run(HandlerThread.java:65)
E/CameraEngine: EXCEPTION: Handler thread is gone. Replacing.
E/CameraEngine: EXCEPTION: Scheduling on the crash handler...

Update:
Please kindly refer to ML Kit Face Verification. It recognizes and extracts key features of the face in the template, compares the features with those of the face in the input image, and then determines whether the two faces belong to the same person based on their similarity.
To achieve liveness detection and face detection/face recognition, there are two services we need: liveness detection service and face detection (Actually face comparison service, which will be supported in 2021.) Currently, HMS Liveness Detection does not support the method of CameraView (by taking the input frames) to achieve face recognition. You may try this two services: Facial recognition (LocalAuthentication Engine) or Facial comparison (HiAI Engine).
Q: Can the HMS take the input frames from CameraView, instead of
opening another camera?
No, it cannot take input frames from CameraView. Because the liveness detection is a multi-frame detection solution. Currently, the logic of frame sending is encapsulated. You app only needs to apply for the camera permission and use the camera on the device for identification or detection.

Related

how to send a link of plant UML configuration

I have an activity diagram created in plantUML:
#startuml
|#LightBlue|ILC Running Continously|
start
note
ILC grabs data from
VOLTTRON message bus
for HVAC system
and electric meter
end note
repeat :Calculate averaged power;
repeat
repeat while (Is Averaged Power above "Demand Limit"?) is (no)
->yes;
repeat: Calculated needed demand reduction;
:Calculate AHP Wieghts;
:Curtail selected loads;
note
Typical to VOLTTRON edge
device on interacting
with building systems via
protocol driver framework
end note
:Wait in Minutes "Control Time";
backward: Curtail more;
note
Devices already curtailed
saved in ILC agent memory
end note
repeat while (Is "Demand Limit" goal met?) is (no)
->yes;
backward: Manage Demand;
#enduml
Is it possible to send someone a link of the entire configuration which is NOT just the output picture link which is in the snip below but the entire configuration for someone else to modify?!
I don't know whether or not it is documented anywhere but from experience / trial error and observing the URLs with the plantuml webserver one can see that the URLs are:
uml: http://www.plantuml.com/plantuml/uml/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000
png: http://www.plantuml.com/plantuml/png/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000
svg: http://www.plantuml.com/plantuml/svg/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000
ASCII art: http://www.plantuml.com/plantuml/txt/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000
in other words the part uml / png / svg /txt changes according to the outcome.
Also when one tries a none existing part it is reverted back to uml

How to Execute (Vector) Storage.getInstance().readObject(filePath); in Java 8 Swing Package

Windows 10 Pro
Latest Simulator
Java Swing Project
I would like to execute "Vector a1 = (Vector) Storage.getInstance().readObject(filePath);"
In a Java Swing Application running on Windows 10 platform, I tried import CodenameOne.jar in Swing package, however when executing above code, get null pointer exception in Storage.getInstance()
Is there a way to execute this in Swing?
Thoughts?
Best Regards.
Thanks, I did not init the Display, however "Display.init(Object m)" requires an Object Argument and the Init method is deprecated.
Can you please provide me the codenameone Display dependencies?
And perhaps a java Swing snippet of code to initialize Display in order to execute Storage.getInstance().readObject(filePath)
Thoughts?
Best Regards
Thanks, Passing init(working directory) solved the Exception thrown.
Here is the Code snippet used to allow me to execute:
Storage.getInstance().readObject(filePath).
String filePath = incSrv.Pwd();// gets working directory
try {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
Display.init(filePath);
String fileName = "A1-MMA.properties";
Vector a1 = (Vector) Storage.getInstance().readObject(filePath);
}
});
} catch (Exception e) {
}
And it does appear to work,
However I am left with a blacked out form that appears modal.
How can I avoid this or dispose it?.
FYI: What I am creating here is a work around for serializing Vector in Codenameone. I Save Vector to file using "Storage.getInstance().writeObject(Path, Vector)"
I convert the file to bytes and write it to the Swing Server VIA socket.
Using Storage.getInstance().readObject(file) on the Swing Server I have deserialize the object into the Vector from my app.
This appears to work well and is more efficient than the current method I use to deliver complex Vectors from the app to the Swing Server.
Can you please let me know if you see a red flag with this workaround?
Like The ability to Storage.getInstance().readObject(file) on the Swing Server may go away?
This method will save a lot of time in movind Vector data to and from the App/Server.
Thoughts Best Regards
Storage.getInstance().readObject(file) // (A1ServiceSrv.java:571)
Caused this Exception:
java.lang.NullPointerException
at com.codename1.io.Storage.init(Storage.java:89)
at com.codename1.io.Storage.getInstance(Storage.java:112)
at Main.A1ServiceSrv.loadVectorFromFile(A1ServiceSrv.java:571)
Regards
12/11/2021:
Thanks Shai,
I am including in my classpath CodenameOne.jar with update date of 12/11/2021 after CN1 refresh.
Getting Same null pointer exception.
Passing in Path "C:\Src1\A1-Arms\A1-Server\A1-MMA.properties" (Absolute Path)
Also Tried "A1-MMA.properties", however I don't think Codenameone knows where my home path is since we are not initializing it as we did with
Display.init("Current Working Directory where files reside");
This is the Fresh Stack Trace w/o calling Display.init (12-20-2021)
java.lang.NullPointerException at
com.codename1.ui.Display.getResourceAsStream(Display.java:3086)
at com.codename1.io.Log.print(Log.java:327)
at com.codename1.io.Log.logThrowable(Log.java:299)
at com.codename1.io.Log.e(Log.java:285)
at com.codename1.io.Storage.readObject(Storage.java:271)
at Main.A1ServiceSrv.loadVectorFromFile(A1ServiceSrv.java:596)
vector = (Vector) Storage.getInstance().readObject(filePath); // (A1ServiceSrv.java:596)
This is hopefully fixed by this commit: https://github.com/codenameone/CodenameOne/commit/72bf283bdaaefe5207bb9fd6787578e3ef61522c if not let me know with a fresh stack

Documentation for SupervisingRouteController

I have MQTT route like below
from("paho:mytopic?brokerUrl=tcp://0.0.0.0:1883&clientId=ipc)
.routeId("myroute")
.to("log:my?showAll=true&multiline=true");
it starts only if broker is available and after that if it lost connectivity with broker it handle it very well and resume.
But my concern is how i can start first time if broker is not available?
I searched on google and got to know  "SupervisingRouteController" might help in this regard, But no document is available how i can use it.
By some hit and trial i reach this point but what further i can do as no document available
final Main main = new Main();
main.addRouteBuilder(new MyMqttRoute());
SupervisingRouteController controller = main.getCamelContexts().get(0).getRouteController().unwrap(SupervisingRouteController.class);
main.run();
Here are two unit test cases that shows usage of SupervisingRouteController.
SupervisingRouteControllerTest.java
SupervisingRouteControllerRestartTest.java
These may be helpful in understanding its usage.

How to register own protocol using the WebBrowser control?

In a WP7 Silverlight application with a WebBrowser control I want to use an own protocol like "myttp://" to deliver some local content. I can't use Navigate() to an IsolatedStrorage because some content will by created on demand. For the same reason NavigateToString() is also not usable for me.
I tried to register a WebRequestCreator descend for my MYTP protocol
myCreator = new MyRequestCreator();
WebRequest.RegisterPrefix("mytp://", myCreator);
but it isn't called from the browser control if I navigate to "mytp://test.html".
If I create a WebRequest via code
WebRequest request;
request = WebRequest.Create("mytp://test.html");`
everythings works fine.
Any suggestions what is wrong or how to do it?
The WebBrowser control will use the Windows Phone Internet Explorer Browser's HTTP stack to statisfy web requests. This HTTP stack is entirely separate from the Client HTTP stack being used by the application. Hence the browser does not see your protocol at all.
I agree with AnthonyWJones words, though I dont know, what exactly he meant by "Browser HTTP stack".
The standard Silverlight's "access to Browser's stack" (used to handle sessions etc) in form of System.Net.Browser.WebRequestCreator.BrowserHttp httprequest factory (versus the "normal/aside" System.Net.Browser.WebRequestCreator.ClientHttp factory) is actually available to the application code in WP7. It is hidden from the SDK, but available on the device and with small effort, the application can use it, for example, to have its emitted cookies in sync with the Browser's cache. For description, please see my humble other post
However, while using that factory and having all your session/cookies/userauth handling within those connections in sync with the WebBrowser, despite being very similar to the ClientHttp factory, you find (at least in 7.0 and 7.1 versions) that it is completely ignorant of any custom prefixes. Trying to open anything with this factory results in (WP7 v. Mango 7.1):
A first chance exception of type 'System.Net.ProtocolViolationException' occurred in System.Windows.dll
at System.Net.Browser.BrowserHttpWebRequest.InternalBeginGetRequestStream(AsyncCallback callback, Object state)
at System.Net.Browser.AsyncHelper.BeginOnUI(BeginMethod beginMethod, AsyncCallback callback, Object state)
at System.Net.Browser.BrowserHttpWebRequest.BeginGetRequestStream(AsyncCallback callback, Object state)
at MyApp.MyPage..ctor()
relevant code snippet of the MyPage:
public class WRC : IWebRequestCreate { public WebRequest Create(Uri uri) { return null;/*BREAKPOINT1*/ } }
WebRequest.RegisterPrefix("js://", new WRC()); // register the above handler
brwHttp = (IWebRequestCreate)typeof(System.Net.Browser.WebRequestCreator).GetProperty("BrowserHttp").GetValue(null, null);
var tmp = brwHttp.Create(new Uri("js://blah.blah.blah"));
var yyy = tmp.BeginGetResponse(callback, "wtf");
var response = tmp.EndGetResponse(yyy); /*BREAKPOINT2*/
var zzz = tmp.BeginGetRequestStream(callback, "wtf"); /*<---EXCEPTION*/
var stream = tmp.EndGetRequestStream(zzz); /*BREAKPOINT3*/
Execution results:
breakpoint1 never hit
breakpoint2 allows to see that "response" is NULL
breakpoint3 never hit due to the exception pasted above
My conclusion is, that the Silverlight Browser's stack is hardcoded to use some builtin set of prefixes, and all other prefixes are ignored/throw ProtocolViolation. My guess is, that in WP7 (7.0, 7.1) they are actually hardcoded to use http since my custom "js://" was passed to a BrowserHttpWebRequest.InternalBeginGetRequestStream as it's visible on the stacktrace :)
That confirms what Anthony had written - no way of having custom protocol handlers to work gracefully with the Silverlight's Browser Stack API.
However, I cannot agree with that the WebBrowser uses this connection factory. While is it true that the hidden factory is called BrowserHttp, and is true that it shares some per-user or per-session settings with the webbrowser, everything I try tens to indicate that the WebBrowser component uses yet completly other factory for its connections, and quite probably it is some native one. As an argument for that, I can only provide that I was able to successfully replace the original BrowserHttp factory with my simple custom implementation of it (both on the emulator and the phone), and with at least 6 webbrowsers in my current app, it wasn't used at all, not even once! (neither on the emulator, nor phone)

What is the easiest way to send GPS info to a server from a BADA OS phone?

Am currently developing a GPS powered solution for tracking field units, and I plan to use Samsung's BADA OS powered phones (affordable but powerful). The only problem am now facing, is i don't know the easiest way to obtain GPS info from the phone (a GT-S5333) to a server (probably via a GET). What can I do?
I've searched for available options and they might not be very friendly as this app doesn't even require an interface on the phone, just sending of the GPS info to a server. Samsung provides a C++ api for Bada (but I think this might be over-kill for this sort of task.)
The other option might be using Webwag's widget api, but I've tried it already, and it doesn't even seem to be possible to do anything beyond RSS widgets.
Might someone help?
Eventually, I did learn about the possibility of using J2ME's Location API, and indeed it is supported on Bada OS phones (virtually any modern phone). So I went for it, and this is how I would obtain my device's location:
import javax.microedition.location.*;
private String reportLocation(Form mainForm){
Criteria cr= new Criteria();
cr.setHorizontalAccuracy(500);
final LocationProvider lp= LocationProvider.getInstance(cr);
new Thread(){
public void run(){
lp.setLocationListener(PatrolGPSDevice.this, 30, -1, -1);
}
}.start();
Location l = lp.getLocation(60);
Coordinates c = l.getQualifiedCoordinates();
if(c != null ) {
double lat = c.getLatitude();
double lon = c.getLongitude();
//do what I want with the location data -- in this case, send it to a server
}

Resources