SeetaFace2 编译出的动态库集成到 Android 项目
欢迎入群交流
QQ群:686809487
下载 opencv android
在这里插入图片描述新建 Android 项目,将 SeetaFace2 编译出的动态库放到 jniLibs 目录下,并在 build.gradle 中指定 jniLibs 库的路径
在这里插入图片描述将 opencv android 目录下的 lib 库拷贝到 Android jniLibs 目录下
seeta_13.png引入头文件
seeta_14.pngCMakeLists.txt 文件
cmake_minimum_required(VERSION 3.4.1)
set(rootPath ${CMAKE_SOURCE_DIR}/../../jniLibs/${CMAKE_ANDROID_ARCH_ABI})
message(${rootPath})
add_library(libSeetaFaceDetector.so SHARED IMPORTED)
set_target_properties(libSeetaFaceDetector.so PROPERTIES IMPORTED_LOCATION ${rootPath}/libSeetaFaceDetector.so)
add_library(libSeetaFaceLandmarker.so SHARED IMPORTED)
set_target_properties(libSeetaFaceLandmarker.so PROPERTIES IMPORTED_LOCATION ${rootPath}/libSeetaFaceLandmarker.so)
add_library(libSeetaFaceRecognizer.so SHARED IMPORTED)
set_target_properties(libSeetaFaceRecognizer.so PROPERTIES IMPORTED_LOCATION ${rootPath}/libSeetaFaceRecognizer.so)
add_library(libSeetaFaceTracker.so SHARED IMPORTED)
set_target_properties(libSeetaFaceTracker.so PROPERTIES IMPORTED_LOCATION ${rootPath}/libSeetaFaceTracker.so)
add_library(libSeetaNet.so SHARED IMPORTED)
set_target_properties(libSeetaNet.so PROPERTIES IMPORTED_LOCATION ${rootPath}/libSeetaNet.so)
add_library(libSeetaQualityAssessor.so SHARED IMPORTED)
set_target_properties(libSeetaQualityAssessor.so PROPERTIES IMPORTED_LOCATION ${rootPath}/libSeetaQualityAssessor.so)
add_library(libopencv_java4.so SHARED IMPORTED)
set_target_properties(libopencv_java4.so PROPERTIES IMPORTED_LOCATION ${rootPath}/libopencv_java4.so)
include_directories(
include/opencv2
include/seeta
include
)
add_library(
facemark
SHARED
face_mark.cpp
ndk_callback.cpp
)
target_link_libraries(
facemark
libSeetaFaceDetector.so
libSeetaFaceLandmarker.so
libSeetaFaceRecognizer.so
libSeetaFaceTracker.so
libSeetaNet.so
libSeetaQualityAssessor.so
libopencv_java4.so
android
log)
目录说明:
assets 目录是下载的模型
include 中引入 opencv2 和 seeta 的头文件
demo 参考
extern "C"
JNIEXPORT void JNICALL
Java_vl_test_FaceManager_test(JNIEnv *env, jobject thiz) {
SDK_LOG_D("picMark");
seeta::ModelSetting::Device device = seeta::ModelSetting::CPU;
int id = 0;
seeta::ModelSetting FD_model("/data/data/vl.test/files/model/fd_2_00.dat",
device, id);
seeta::FaceTracker FD(FD_model);
FD.set(seeta::FaceTracker::PROPERTY_VIDEO_STABLE, 1);
cv::Mat frame = cv::imread("/data/data/vl.test/files/camera/camera1637922203067");
SDK_LOG_D("frame imread height:%d , width:%d", frame.rows, frame.cols);
seeta::cv::ImageData simage = frame;
auto faces = FD.track(simage);
SDK_LOG_D("faces:%d", faces.size);
for (int i = 0; i < faces.size; ++i) {
auto &face = faces.data[i];
// 坐标值
cv::rectangle(frame, cv::Rect(face.pos.x, face.pos.y, face.pos.width, face.pos.height),
CV_RGB(128, 128, 255), 3);
}
std::string filePath = "/data/data/vl.test.app/files/camera/test_temp.jpg";
cv::imwrite(filePath, frame);
SDK_LOG_D("frame imwrite height:%d , width:%d", frame.rows, frame.cols);
}
在这里插入图片描述
微信公众号(他晓),关注并转发,谢谢
网友评论