当前位置:网站首页>Application of hongruan face recognition
Application of hongruan face recognition
2022-06-30 09:02:00 【Silent Pinocchio】
Application of hongruan face recognition
I have been busy with my work before , There is no time to update the blog , Now we have time , Just share a wave of dry goods with you .
About face recognition , I used Baidu before , The last two have used hongruan , Next, I will introduce the advantages and disadvantages of both . Compared with rainbow soft , Baidu's face recognition needs to rely on the Internet , Longer time consuming , But Baidu's recognition is accurate .
Hongruan's face recognition is applied and developed offline , Because you don't need a network , So its recognition speed is faster . But its recognition is not high , For example, compare two pictures , Compare with Baidu , The similarity may reach 90% above , But the possibility of hongruan will reach 60% about . Baidu's operation is relatively simple . in general , Which one to choose depends on your needs .
Okay , I don't say much nonsense , Next, I will teach you how to use it .
1. The first is to apply on the official website APPKEY, Various keys , Then download jar package , These will not be explained to you one by one . Pay attention to the , To be in app Of gradle Inside plus
sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}
this sentence , Otherwise, it may cause so The library cannot be loaded .
2. Next, we need to develop .
Take the function of face detection for example , The first thing you need to
Initialize the engine ,
AFD_FSDKEngine engine1 = new AFD_FSDKEngine();
AFD_FSDKError err = engine1.AFD_FSDK_InitialFaceEngine(Config.APP_ID, Config.FD_KEY, AFD_FSDKEngine.AFD_OPF_0_HIGHER_EXT, 16, 5);`
We also need a collection , Used to store the faces we detected ,
List<AFD_FSDKFace> result = new ArrayList<AFD_FSDKFace>();// newly build AFD_FSDKFacejihe, Used to store the recognized face information
Then we can carry out face detection , But there are requirements for the selection and format of photos , So we need to format the photos .
Bitmap bitmap1 = decodeImage(path1);//path Is the path of the photo , Select photos first , Turn into bitmap
byte[] data1 = getNv21(bitmap1);// then bitmap Turn into NV21 Format
Here's the tool class decodeImage and getNv21 Code for
//getNv21 and decodeImage It is a conversion tool for Photo format
public byte[] getNv21(Bitmap mBitmap) {
byte[] data = new byte[mBitmap.getWidth() * mBitmap.getHeight() * 3 / 2];
ImageConverter convert = new ImageConverter();
convert.initial(mBitmap.getWidth(), mBitmap.getHeight(), ImageConverter.CP_PAF_NV21);
if (convert.convert(mBitmap, data)) {
Log.e("TAG", "convert ok!");
}
convert.destroy();
return data;
}
public static Bitmap decodeImage(String path) {
Bitmap res;
try {
ExifInterface exif = new ExifInterface(path);
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
BitmapFactory.Options op = new BitmapFactory.Options();
op.inSampleSize = 1;
op.inJustDecodeBounds = false;
//op.inMutable = true;
res = BitmapFactory.decodeFile(path, op);
//rotate and scale.
Matrix matrix = new Matrix();
if (orientation == ExifInterface.ORIENTATION_ROTATE_90) {
matrix.postRotate(90);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_180) {
matrix.postRotate(180);
} else if (orientation == ExifInterface.ORIENTATION_ROTATE_270) {
matrix.postRotate(270);
}
Bitmap temp = Bitmap.createBitmap(res, 0, 0, res.getWidth(), res.getHeight(), matrix, true);
Log.d("com.arcsoft", "check target Image:" + temp.getWidth() + "X" + temp.getHeight());
if (!temp.equals(res)) {
res.recycle();
}
return temp;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
After converting the format , The face detection started .
err = engine1.AFD_FSDK_StillImageFaceDetection(data1, bitmap1.getWidth(), bitmap1.getHeight(), AFD_FSDKEngine.CP_PAF_NV21, result);
Log.e("TAG", "getBit: " + result.size());
We can view collections result Of size, To determine if a face is detected .
At the end of the code , Be sure to destroy the initialized engine . Otherwise, the program will crash due to memory problems . `
engine1.AFD_FSDK_UninitialFaceEngine();
Face comparison is based on face detection , First detect the face information on a photo , Then compare the face information .
List result = new ArrayList();
That was covered above , The detected face information is stored in result In the collection of ,
Then create two classes to store face point information
AFR_FSDKFace face1 = new AFR_FSDKFace();
AFR_FSDKFace face2 = new AFR_FSDKFace();
Store the point information of the detected face information in face Class
// Two new AFR_FSDKFace class , Save face feature information
AFR_FSDKFace face1 = new AFR_FSDKFace();
AFR_FSDKFace face2 = new AFR_FSDKFace();
// Detection of facial feature information
er = engine_camera.AFR_FSDK_ExtractFRFeature(data_image, bitmap_idcard.getWidth(), bitmap_idcard.getHeight(), AFR_FSDKEngine.CP_PAF_NV21, new Rect(result_image.get(0).getRect()), result_image.get(0).getDegree(), face1);
er = engine_camera.AFR_FSDK_ExtractFRFeature(data, wid, hei, AFR_FSDKEngine.CP_PAF_NV21, new Rect(result_fd.get(0).getRect()), result_fd.get(0).getDegree(), face2);
The similarity information of the final comparison is stored in score in ,
float score_face = score.getScore();
We can get... In this way The similarity information we want , The final data is float Type of .
This is the basic use process of hongruan , I wrote about the use of Baidu's face recognition in the previous article , You can have a look , Comparison , Choose according to your needs .
Finally, if there is anything you don't understand , Welcome to comment and ask questions , You can also add my QQ1064902365 Consultation .
Reprint please indicate the source
边栏推荐
- Rew acoustic test (VI): signal and measurement
- Interpretation of source code demand:a rotation equivariant detector for aerial object detection
- C#訪問SQL Server數據庫兩種方式的比較(SqlDataReader vs SqlDataAdapter)
- Influencing factors of echo cancellation for smart speakers
- Detectron2 source code reading 2--- using the configurable decorator to build the dataloader
- Rew acoustic test (III): generate test signal
- Flink sql -- No factory implements ‘org. apache. flink. table. delegation. ExecutorFactory‘.
- vite项目require语法兼容问题解决require is not defined
- Redis design and Implementation (I) | data structure & object
- 关于Lombok的@Data注解
猜你喜欢
Installation, use and explanation of vulnerability scanning tool OpenVAS
C#访问MongoDB并执行CRUD操作
Wechat development tool (applet)
Esp32 things (3): overview of the overall system design
Flink SQL custom connector
Redis design and Implementation (V) | sentinel sentry
Bind threads to run on a specific CPU logical kernel
技术管理进阶——管理者如何进行梯队设计及建设
Pytorch BERT
Enhance the add / delete operation of for loop & iterator delete collection elements
随机推荐
挖财开户安全吗?怎么有人说不靠谱。
C # get the current timestamp
Invalid update: invalid number of sections. The number of sections contained in the table view after
How can I get the discount for opening a securities account? Is online account opening safe?
vite项目require语法兼容问题解决require is not defined
Design specification for smart speakers v1.0
127.0.0.1, 0.0.0.0 and localhost
Esp32 (6): Bluetooth and WiFi functions for function development
Mmdet line by line code interpretation of positive and negative sample sampler
Circuit analysis of current probe
Redis design and Implementation (II) | database (deletion strategy & expiration elimination strategy)
Introduction to MySQL basics day4 power node [Lao Du] class notes
Interviewer: do you understand the principle of recyclerview layout animation?
Use Huawei performance management service to configure the sampling rate on demand
Raspberry pie 4B no screen installation system and networking using VNC wireless projection function
【付费推广】常见问题合集,推荐榜单FAQ
Based on svelte3 X desktop UI component library svelte UI
Duplicate entry '2' for key 'primary appears in JPA‘
Six implementation methods of singleton mode
Implementing custom drawer component in quick application