当前位置:网站首页>Face++ realizes face detection by flow
Face++ realizes face detection by flow
2022-06-25 06:20:00 【mjlong123123】
We use face detection sdk The process of face recognition can be roughly divided into the following steps :
- load model File and initialize the interface
- Get authorization
- Call face detection to get key points
- Notice the key points of the drawing
- Release interface resources
Here are the steps 3 and 4 On receiving camera Execute repeatedly after data . We can abstract these steps into data flow for encapsulation .face++ Face coordinates are generated continuously after face detection , So the whole detection process is the process of face coordinate data production , Here with flow The concept of corresponds to .
face++ Need to deal with camera Data to get face key points , therefore camera again face++ Face detection api Data providers for . The following figure shows the process of data flow :

Seeing this, people also think that we passed flow It is more reasonable to realize this process ! Let's implement it step by step detect flow The creation of .
The first step is to pass flow Of builder Create a flow:
private val imageChannel = Channel<FacePPImage>()
flow {
while (currentCoroutineContext().isActive) {
emit(imageChannel.receive())
}
}
Use here Channel To receive image data and transmit . stay detect flow We also need some initialization before processing image data face++ The job of , These work in onStart In dealing with .
flow.onStart {
var ret = -1
context.assets.open("megviifacepp_model").use { ios ->
modelBuffer = ByteArray(ios.available())
ios.read(modelBuffer)
FaceppApi.getInstance().setLogLevel(4)
ret = FaceppApi.getInstance().initHandle(modelBuffer)
}
if (ret != 0) {
Log.d("dragon_debug", " onStart open failed!")
throw RuntimeException("init")
}
if (requestTakeLicense && modelBuffer != null) {
Log.d("dragon_debug", " onStart takeLicense")
ret = takeLicense(context, modelBuffer!!)
}
if (ret != 0) {
Log.d("dragon_debug", " onStart takeLicense failed!")
throw RuntimeException("takeLicense")
}
ret = FaceDetectApi.getInstance().initFaceDetect()
DLmkDetectApi.getInstance().initDLmkDetect()
if (ret != 0) {
if (requestTakeLicense) {
Log.d("dragon_debug", " onStart initFaceDetect error")
throw RuntimeException("error")
}
requestTakeLicense = true
Log.d("dragon_debug", " onStart initFaceDetect retry exception")
throw RuntimeException("initFace")
}
val config = FaceDetectApi.getInstance().faceppConfig
config.face_confidence_filter = 0.6f
config.detectionMode = FaceDetectApi.FaceppConfig.DETECTION_MODE_TRACKING
FaceDetectApi.getInstance().faceppConfig = config
}
face++ The initialization operation includes loading the model 、 Detect interface authorization 、 Face detection interface initialization and other steps .
The detection interface authorization processing is somewhat special ,face++ The interface authorization of is only executed when the authorization expires . So here we go flow Of retryWhen To handle expired authorizations .
flow.retryWhen { cause, attempt ->
Log.d("dragon_debug", " retryWhen $cause attempt $attempt")
if (attempt > 1) {
false
} else {
(cause as? RuntimeException)?.message?.equals("initFace") ?: false
}
}
First try to initialize face++ Interface , If initialization fails , An exception will be thrown here RuntimeException("init").retryWhen Catch this exception and initiate retry processing , When onStart When executed again , We will try to obtain the interface permission .
face++ After the interface authorization is initialized successfully , We can use face++ Face detection interface . Use here map Converting image data into face coordinate data , Conversion operation by face++ Face detection interface is completed .
flow.map { image ->
val faces = FaceDetectApi.getInstance().detectFace(image)
faces.forEach { face ->
FaceDetectApi.getInstance().getLandmark(face, FaceDetectApi.LMK_84, true)
}
block.invoke(faces)
faces
}
The obtained face coordinate data passes through block Callback notification screen drawing .
face++ The release operation of the interface is in onCompletion in ,
flow.onCompletion {
Log.d("dragon_debug", " onCompletion ")
FaceppApi.getInstance().ReleaseHandle()
DLmkDetectApi.getInstance().releaseDlmDetect()
}
Complete code :GitHub - mjlong123123/FaceDetectorFlow
边栏推荐
- Count the grid
- An interview question record about where in MySQL
- Analysis report on demand scale and Supply Prospect of global and Chinese thermal insulation materials market during the 14th Five Year Plan period 2022-2028
- Research Report on global and Chinese vaccine market profit forecast and the 14th five year plan development strategy 2022-2028
- Optimal Parking
- Go quiz: considerations for function naming return value from the go interview question (more than 80% of people answered wrong)
- Jz-066- motion range of robot
- Vscode voice notes to enrich information (Part 1)
- Technology inventory: past, present and future of Message Oriented Middleware
- Find command – find and search for files
猜你喜欢

Hands on deep learning (III)

IQ debugging of Hisilicon platform ISP and image (1)

Folding mobile phones are expected to explode, or help Samsung compete with apple and Chinese mobile phones

Asemi fast recovery diode us1m parameters, us1m recovery time, us1m voltage drop
The e-book "action guide for large organizations to further promote zero code application platform" was officially released!

No one reads the series. Source code analysis of copyonwritearraylist
Vscode voice notes to enrich information (Part 1)

Laravel8 fill data

Click to send text messages without response is a common problem for many users in building the elegant grass Dragonfly Q system - solve the problem of clicking to send text messages without response
SAP ui5 beginner tutorial No. 28 - Introduction to the integration test tool OPA for SAP ui5 applications
随机推荐
Optimal Parking
Add the author watermark plugin v1.4 update to the posts of elegant grass discuz plugin - some forums post errors and bugs have been fixed
The sum problem
Invalid bound statement (not found)
VMware virtual machine prompt: the virtual device ide1:0 cannot be connected because there is no corresponding device on the host.
How often should you refactor- How often should you refactor?
MySQL uses the where condition to find strange results: solve
MySQL transaction learning notes (I) first encounter
SAP ui5 application development tutorial XXIX - Introduction to routing and navigation functions of SAP ui5 trial version
Getting started with Silverlight development 1
Uname command – displays system information
The e-book "action guide for large organizations to further promote zero code application platform" was officially released!
PHP output (print) log to TXT text
[road of system analyst] collection of wrong questions in the chapters of Applied Mathematics and economic management
MySQL tuning -- 02 -- slow query log
An easy problem
Why study discrete mathematics
Gavin's insight on transformer live class - line by line analysis and field experiment analysis of insurance BOT microservice code of insurance industry in the actual combat of Rasa dialogue robot pro
Global and China financial guarantee marketing strategy and channel dynamic construction report 2022
Go quiz: considerations for function naming return value from the go interview question (more than 80% of people answered wrong)