当前位置:网站首页>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
边栏推荐
- [untitled]
- 100 lines of code and a voice conversation assistant
- Anchorgenerator for mmdet line by line interpretation
- Advanced technology management -- how managers design and build echelons
- Introduction to MySQL basics day4 power node [Lao Du] class notes
- El input limit can only input numbers
- Abstract factory pattern
- Qt通过Url下载文件
- Pytorch BERT
- Opencv learning notes -day13 pixel value statistics calculation of maximum and minimum values, average values and standard deviations (use of minmaxloc() and meanstddev() functions)
猜你喜欢

Self made GIF dynamic graph -gifcam

Esp32 (4): overview of the overall code architecture

Opencv learning notes -day2 (implemented by the color space conversion function cvtcolar(), and imwrite image saving function imwrite())

Redis design and Implementation (V) | sentinel sentry

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

Flink Sql -- toAppendStream doesn‘t support consuming update and delete changes which

Opencv learning notes -day3 (mat object and creation related operations mat:: clone(), mat:: copyto(), mat:: zeros(), mat:: ones(), scalar()...)

快应用中实现自定义抽屉组件

Anchorgenerator for mmdet line by line interpretation

Interference source current spectrum test of current probe
随机推荐
JVM tuning related commands and explanations
Set, map and modularity
[kotlin collaboration process] complete the advanced kotlin collaboration process
Flink SQL custom connector
Unity basic lighting model
Occasionally, Flink data is overstocked, resulting in checkpoint failure
[untitled]
Metasploit practice - SSH brute force cracking process
Summary of common pytoch APIs
Understanding society at the age of 14 - reading notes on "happiness at work"
Is the reverse repurchase of treasury bonds absolutely safe? How to open an account online
Talk about how the kotlin process started?
Build a docker image of Henkel database from 0
Using appbarlayout to realize secondary ceiling function
Maxiouassigner of mmdet line by line interpretation
Rew acoustic test (IV): test principle of rew
Resnet50+fpn for mmdet line by line code interpretation
Axure make menu bar effect
Esp32 (6): Bluetooth and WiFi functions for function development
[untitled]