当前位置:网站首页>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
边栏推荐
- Wikimedia Foundation announces the first customers of its new commercial product "Wikimedia enterprise"
- [data analysis and display]
- Coredata acquisition in swift sorting, ascending, descending
- Maxiouassigner of mmdet line by line interpretation
- Icon resources
- Sort (simple description)
- Influencing factors of echo cancellation for smart speakers
- Rew acoustic test (I): microphone calibration
- mysql基础入门 动力节点[老杜]课堂作业
- layer. Open processing method when the passed value is an array or the value is too long
猜你喜欢
![[untitled]](/img/45/368c41a74bf0738369c58c5963fca0.jpg)
[untitled]

Metasploit practice - SSH brute force cracking process

Codeworks 5 questions per day (1700 for each) - the third day

100 lines of code and a voice conversation assistant

Mmdet line by line deltaxywhbboxcoder

Pytorch BERT
![[data analysis and display]](/img/86/19260ee664769c98588d8b0783ef28.jpg)
[data analysis and display]

Bind threads to run on a specific CPU logical kernel

TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush

Redis design and Implementation (VI) | cluster (sharding)
随机推荐
Detailed explanation of rect class
Redis design and Implementation (VI) | cluster (sharding)
Esp32 things (I): Preface
Pytorch BERT
将线程绑定在某个具体的CPU逻辑内核上运行
Sort (simple description)
Esp32 (IX): OTA function of function development
技术管理进阶——管理者如何进行梯队设计及建设
Evaluation standard for audio signal quality of intelligent speakers
Redis design and Implementation (V) | sentinel sentry
Understanding of MVVM and MVC
[JPEG] how to compile JPEG turbo library files on different platforms
Opencv learning notes -day2 (implemented by the color space conversion function cvtcolar(), and imwrite image saving function imwrite())
127.0.0.1, 0.0.0.0 and localhost
vim 从嫌弃到依赖(21)——跨文件搜索
关于Lombok的@Data注解
Coredata acquisition in swift sorting, ascending, descending
挖财开户安全吗?怎么有人说不靠谱。
TiDB v6.0.0 (DMR) :缓存表初试丨TiDB Book Rush
Comparison of two ways for C to access SQL Server database (SqlDataReader vs SqlDataAdapter)