dlib android 识别时间,android dlib调用

1、在cmakelist.txt中加入:

include(src/main/cpp/dlib/cmake)

然后再链接dlib库就可以了:

target_link_libraries( # Specifies the target library.

native-lib

dlib

# Links the target library to the log library

# included in the NDK.

${log-lib} )

2、可能出现的错误

Android NDK 编译器默认不支持 C++ 异常控制导致。

Error:(124, 17) error: cannot use 'throw' with exceptions disabled

Error:(119, 21) error: cannot use typeid with -fno-rtti

在build.gradle中加入cpp编译选项:

cppFlags "-fexceptions"

cppFlags "-frtti"

最后build文件如下:

compileSdkVersion 24

buildToolsVersion "24.0.1"

defaultConfig {

applicationId "image.imageapp"

minSdkVersion 19

targetSdkVersion 24

versionCode 1

versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

externalNativeBuild {

cmake {

cppFlags "-std=c++11"

cppFlags "-fexceptions"

cppFlags "-frtti"

}

}

}

4、找不到opencv.cmake

SET(OpenCV_INCLUDE_DIRS "/usr/include")

SET(OpenCV_LIB_DIR "/usr/lib")

INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})

5、找不到

gnu/stubs-64.h那么:

apt-get install libc6-dev-amd64

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用dlib实现人脸识别的具体流程如下: 1. 安装dlib:在命令行中使用pip install dlib安装dlib库。 2. 下载人脸检测器模型:从dlib官网下载一个训练好的人脸检测器模型,例如shape_predictor_68_face_landmarks.dat文件。 3. 导入必要的库:导入dlib、cv2(OpenCV)和numpy库。 4. 加载图像:使用cv2.imread函数加载待识别的图像。 5. 缩放图像:如果图像太大,可以使用cv2.resize函数将其缩小至合适大小。 6. 人脸检测:使用dlib.get_frontal_face_detector函数检测图像中的人脸,并返回人脸位置的列表。 7. 特征提取:使用dlib.face_recognition_model_v1函数将每个检测到的人脸转换为128维的向量表示。 8. 人脸匹配:将待识别人脸的向量与已知人脸的向量进行匹配,可以使用欧式距离(Euclidean distance)或余弦相似度(Cosine similarity)进行比较。 9. 输出结果:将匹配结果输出到屏幕上或保存到文件中。 以下是一个基本的示例代码: ``` import dlib import cv2 import numpy as np # 下载并加载人脸检测器模型 detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") # 加载待识别的图像 img = cv2.imread("test.jpg") # 缩放图像 img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5) # 人脸检测 faces = detector(img, 1) # 特征提取 face_descriptors = [] for face in faces: shape = predictor(img, face) descriptor = np.array(face_descriptor.compute_face_descriptor(img, shape)) face_descriptors.append(descriptor) # 人脸匹配 known_faces = [...] # 已知人脸的向量 for descriptor in face_descriptors: distances = np.linalg.norm(known_faces - descriptor, axis=1) min_distance = np.min(distances) if min_distance < threshold: index = np.argmin(distances) print("Matched with person", index) else: print("Unknown person") ``` 请注意,示例代码仅提供了基本的流程和框架,实际使用中还需要根据具体需求进行修改和完善。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值