Visual Service
Visual service provides face detection, face recognition, face tracking and other services.
Face detection,Detect whether there is a face in the camera image or target image, and if so, return the position, size and angle of the face.
Face recognition,By extracting human facial features, the similarity between two faces is calculated to determine whether they are the same person
Face tracking,Face key point location and tracking technology can accurately locate and track the change of face position.
Initialization
As a visual service access agent, the VisualManager object provides the main API of visual service, which can be obtained as follows:
VisualManager mVisualManager = VisualManager.getInstance(); mVisualManager.init(getApplicationContext()); // Initialization required
Start a visual task
mVisualManager.start(VisualParam param); // param is a visual parameter
The construction method of visual parameters
VisualParam param = new VisualParam.Builder() .requestId(requestId) // Set request ID .requestType(requestType) // Set request type .online(online) // Open online face recognition or not .showUi(showUi) // Display interface or not .timeOut(timeOut) // Set timeout .imageFile(imageFile) // The absolute path of the image passed in during image recognition .imagePath(imagePath) // Set the directory for saving photos when taking pictures of faces .groupId(groupId) // GroupId of online face recognition .build();
VisualParam parameter description
| type | parameter | parameter description | required |
|---|---|---|---|
| String | requestId | It is the unique ID of each request. This ID is returned in the information callback,optional parameter. UUID is generated by default | no |
| int | requestType | int TYPE_DEFAULT = 0; //face registration int TYPE_RECOGNITION = 1; //face recognition int TYPE_DETECTION = 2; //face tracking int TYPE_IMAGE= 3; //Picture recognition, screenshot interface int TYPE_IMAGE_BG= 4; //Picture recognition, no screenshot interface int TYPE_TAKE_PHOTO= 5; //Face photo (In the face registration process, when the face is matched, the user information will be returned online, and the saved face ID will be returned offline; when the face is not matched, the newly generated face ID will be returned) |
yes |
| boolean | online | Whether to use online face recognition? True is online face recognition and false is offline face recognition.(groupid needs to be configured when online) | yes |
| boolean | showUi | Whether to display the interface? True is the display scanning interface, false is the non sensitive face recognition (Requesttype has no interface by default during face detecting. This parameter is ignored) | yes |
| long | timeOut | Timeout,In milliseconds,(No timeout when < = 0) | yes |
| String | groupId | When creating enterprise number, online user management mode is selected by default, and groupid is automatically generated. This item needs to be configured for online face recognition. If the enterprise number is changed, the groupid needs to be updated. (log in CBIS website and click user management to view the groupid or view getstatus method in [user management document][user management documen]. | Required if online |
| String | imageFile | The absolute path of the picture (the request type is picture recognition) | Required when the request type is picture recognition |
| String | imagePath | The saving path of the picture of face photo (request type is face photo) | Required when the request type is face photo |
Note: When the requestType is TYPE_DETECTION = 2 (face tracking), local face detection is adopted, and there is no scan interface, the parameters online, showUi, groupId can be ignored.
Face detection,face tracking:
private void faceDetection() { VisualParam param = new VisualParam.Builder() .requestType(VisualParam.TYPE_DETECTION) .build(); mVisualManager.start(param); }
Offline picture recognition:
private void imageRecognizeLocal(String imageFile) { VisualParam param = new VisualParam.Builder() .requestType(VisualParam.TYPE_IMAGE_BG) .imageFile(imageFile) // Incoming photo path .online(false) // Offline .build(); mVisualManager.start(param); }
Online picture recognition:
private void imageRecognizeOnline(String imageFile, String groupId) { VisualParam param = new VisualParam.Builder() .requestType(VisualParam.TYPE_IMAGE_BG) .imageFile(imageFile) // Incoming image path .online(true) // online .groupId(groupId) // groupId .build(); mVisualManager.start(param); }
Face photo:
private void takeFacePhoto(boolean showUi, String imagePath) { VisualParam param = new VisualParam.Builder() .requestType(VisualParam.TYPE_TAKE_PHOTO) .showUi(showUi) // Whether to display the interface .imagePath(imagePath) // Set the directory for saving photos .build(); mVisualManager.start(param); }
Stop visual task
mVisualManager.stop(); //Stop last task mVisualManager.stop(String requestId); //Stop the specified task, requestId is the unique ID at the time of request
Listener
To obtain the information after the task is finished, you need to register a listening callback.
Add a listener:
mVisualManager.addListener(VisualListener listener);
Remove a listener:
mVisualManager.removeListener(VisualListener listener);
Note:Add and remove need to be paired .
Listener:
public class MyListener extends VisualListener { @Override public void onDone(String message) { // Analyze JSON according to business requirements Log.d(TAG, "onDone : " + message); try { Result result = new Gson().fromJson(message, Result.class); Log.i(TAG, "result : " + result); } catch (Exception e) { Log.e(TAG, "onDone Exception", e); } } @Override public void onFail(int code, String error) { // Code is the error code and error is the error message Log.d(TAG, "onFail code : " + code + ", error : " + error); } @Override public void onProgress(String message) { Log.d(TAG, "onProgress : " + message); } }
Result definition returned in onDone :
| type | parameter | parameter desciption |
|---|---|---|
| String | requestId | The return value is the same as the requestId in the visual parameter VisualParam of the start task |
| int | code | Face recognition return message code int DETECT_FAIL = 224; Face detection failed int RECOGNIZE_FAIL= 225; Face recognition failed int RECOGNIZE_INTERRUPT = 226; Face recognition interrupt int RECOGNIZE_TIME_OUT= 227; Face recognition timeout int CAMERA_OPEN_FAIL= 228; Camera open failed int CANCEL= 229; Cancel task actively int IMAGE_EXCEPTION= 230; Image exception int RECOGNIZE_FAIL_BROKEN= 8208; Face recognition blocking int PHOTO= 160; Take photo successfully int MATCH= 161; Match to face database, face recognition successful int MISMATCH= 162; Face recognition is not matched to face database int EXCEPTION= 163; Abnormal face recognition |
| String | message | Message returned by face recognition "fail" Face recognition is not matched to face database "success" Successful face recognition, matching to face database "exception" Abnormal face recognition "interrupt" Face recognition interrupt "time out;" Face recognition timeout "cancel" Cancel task actively "camera open fail" Camera open failed "image exception" |
| String | faceId | The face ID returned by offline face recognition. If a matching face is found, the saved ID will be returned. Otherwise, the UUID will be generated again. This value can be ignored in online face recognition. |
| String | imageFile | Return to the image path location in face recognition |
| PersonDetail | personDetail | Online face recognition: matching to face returns user details, including name, gender, title, remarks, grouping, face image address, etc., but not matching to face returns NULL; offline face recognition: this value returns null |
When the request parameter is face tracking (requesttype = 2), callback in onProgress function.
| type | parameter | parameter description |
|---|---|---|
| float[] | angles | face angle,[0]pitch angle、[1] left or right roll angle 、[2] inclination angle |
| Rect | rect | The position of the face rectangle in the camera (Note: the resolution of the camera without scan frame is 800 * 600, and the resolution of the camera with scan frame is 1280 * 720) |
Free memory
mVisualManager.onDestroy();