当前位置:网站首页>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
边栏推荐
- 14岁懂社会-《关于“工作的幸福”这件事儿》读书笔记
- Wikimedia Foundation announces the first customers of its new commercial product "Wikimedia enterprise"
- 127.0.0.1、0.0.0.0和localhost
- C # listbox how to get the selected content (search many invalid articles)
- Rew acoustic test (VI): signal and measurement
- [untitled]
- Flink Sql -- toAppendStream doesn‘t support consuming update and delete changes which
- Using appbarlayout to realize secondary ceiling function
- [paid promotion] collection of frequently asked questions, FAQ of recommended list
- Rew acoustic test (V): equipment required for test
猜你喜欢
Mmdet line by line deltaxywhbboxcoder
Redis design and Implementation (V) | sentinel sentry
Evaluation standard for audio signal quality of intelligent speakers
VIM from dislike to dependence (21) -- cross file search
Abstract factory pattern
Explanation on the use of password profiteering cracking tool Hydra
Talk about how the kotlin process started?
Bind threads to run on a specific CPU logical kernel
Redis design and Implementation (VII) | publish & subscribe
Detectron2 source code reading 3-- encapsulating dataset with mapper
随机推荐
Redis design and Implementation (VI) | cluster (sharding)
[untitled]
vite項目require語法兼容問題解决require is not defined
VIM from dislike to dependence (21) -- cross file search
vim 从嫌弃到依赖(21)——跨文件搜索
Rew acoustic test (VI): signal and measurement
Esp32 things (V): analysis of common API of esp32 of Swiss Army knife
Occasionally, Flink data is overstocked, resulting in checkpoint failure
Esp32 (6): Bluetooth and WiFi functions for function development
mysql基础入门 day4 动力节点[老杜]课堂笔记
Interference source current spectrum test of current probe
关于Lombok的@Data注解
How can we get a satisfactory salary? These routines still need to be mastered
Opencv learning notes -day4 image pixel reading and writing operations (array traversal and pointer traversal implementation, uchar vec3b data type and mat class functions mat:: at(), mat:: ptr())
Opencv learning notes -day10 logical operation of image pixels (usage of rectangle function and rect function and bit related operation in openCV)
Talk about writing
vite项目require语法兼容问题解决require is not defined
TiDB 6.0:让 TSO 更高效丨TiDB Book Rush
Esp32 (4): overview of the overall code architecture
Find the number that appears only once in the array