//保存人脸信息Mat,图片jpg
Mat saveMat = Mat(equalize_mat, faceRect);
//保存face_info_mat
imwrite(filePath, equalize_mat);
return 1;
}
env->ReleaseStringUTFChars(name, filePath);
return 0;
}
- 人脸对比
/**
*人脸对比
*/
extern “C”
JNIEXPORT jdouble JNICALL
Java_com_hxg_ndkface_FaceDetection_histogramMatch(JNIEnv *env, jobject instance, jobject bitmap1,
jobject bitmap2) {
//1.Bitmap转成opencv能操作的C++对象Mat
Mat mat, mat1;
bitmap2Mat(env, mat, bitmap1);
bitmap2Mat(env, mat1, bitmap2);
// 转灰度矩阵
cvtColor(mat, mat, COLOR_BGR2HSV);
cvtColor(mat1, mat1, COLOR_BGR2HSV);
int channels[] = {0, 1};
int histsize[] = {180, 255};
float r1[] = {0, 180};
float r2[] =
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
{0, 255};
const float *ranges[] = {r1, r2};
Mat hist1, hist2;
calcHist(&mat, 3, channels, Mat(), hist1, 2, histsize, ranges, true);
//https://www.cnblogs.com/bjxqmy/p/12292421.html
normalize(hist1, hist1, 1, 0, NORM_L1);
calcHist(&mat1, 3, channels, Mat(), hist2, 2, histsize, ranges, true);
normalize(hist2, hist2, 1, 0, NORM_L1);
double similarity = compareHist(hist1, hist2, HISTCMP_CORREL);
__android_log_print(ANDROID_LOG_ERROR, “TTTTT”, “相识度:%f”, similarity);
return similarity;
}
- Dnn模式的人脸识别,并抠图
private void copyCaseCadeFilePbtxt() {
InputStream is = null;
FileOutputStream os = null;
try {
// load cascade file from application resources
is = getResources().openRawResource(R.raw.opencv_face_detector);
File cascadeDir = getDir(“cascade”, Context.MODE_PRIVATE);
mCascadeFile = new File(cascadeDir, “opencv_face_detector.pbtxt”);
if (mCascadeFile.exists()) return;
os = new FileOutputStream(mCascadeFile);
byte[] buffer = new byte[1024 * 1024];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
private void copyCaseCadeFileUint8() {
InputStream is = null;
FileOutputStream os = null;
try {
// load cascade file from application resources
is = getResources().openRawResource(R.raw.opencv_face_detector_uint8);
File cascadeDir = getDir(“cascade”, Context.MODE_PRIVATE);
mCascadeFile = new File(cascadeDir, “opencv_face_detector_uint8.pb”);
if (mCascadeFile.exists()) return;
os = new FileOutputStream(mCascadeFile);
byte[] buffer = new byte[1024 * 1024];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
os.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
}
if (os != null) {
os.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
*Dnn模式的人脸识别,并抠图
*/
extern “C”
JNIEXPORT jboolean JNICALL
Java_com_hxg_ndkface_FaceDetection_faceDnnDetection(JNIEnv *env, jobject instance,
jstring model_binary,
jstring model_desc,
jstring checkPath,
jstring resultPath) {
const char *model_binary_path = env->GetStringUTFChars(model_binary, 0);
const char *model_desc_path = env->GetStringUTFChars(model_desc, 0);
cons