| 7 | #include "inspireface/track_module/landmark/order_of_hyper_landmark.h" |
| 8 | |
| 9 | int main(int argc, char** argv) { |
| 10 | if (argc != 3) { |
| 11 | std::cout << "Usage: " << argv[0] << " <model_path> <image_path>" << std::endl; |
| 12 | return -1; |
| 13 | } |
| 14 | |
| 15 | std::string model_path = argv[1]; |
| 16 | std::string image_path = argv[2]; |
| 17 | |
| 18 | // Global init(only once) |
| 19 | INSPIREFACE_CONTEXT->Reload(model_path); |
| 20 | |
| 21 | // Create image and frame process |
| 22 | inspirecv::Image image = inspirecv::Image::Create(image_path); |
| 23 | inspirecv::FrameProcess process = |
| 24 | inspirecv::FrameProcess::Create(image.Data(), image.Height(), image.Width(), inspirecv::BGR, inspirecv::ROTATION_0); |
| 25 | |
| 26 | // Create session |
| 27 | inspire::CustomPipelineParameter param; |
| 28 | param.enable_recognition = true; |
| 29 | param.enable_liveness = true; |
| 30 | param.enable_mask_detect = true; |
| 31 | param.enable_face_attribute = true; |
| 32 | param.enable_face_quality = true; |
| 33 | param.enable_interaction_liveness = true; |
| 34 | std::shared_ptr<inspire::Session> session(inspire::Session::CreatePtr(inspire::DETECT_MODE_ALWAYS_DETECT, 1, param, 320)); |
| 35 | |
| 36 | INSPIREFACE_CHECK_MSG(session != nullptr, "Session is not valid"); |
| 37 | |
| 38 | // Detect and track |
| 39 | std::vector<inspire::FaceTrackWrap> results; |
| 40 | int32_t ret; |
| 41 | ret = session->FaceDetectAndTrack(process, results); |
| 42 | INSPIREFACE_CHECK_MSG(ret == 0, "FaceDetectAndTrack failed"); |
| 43 | |
| 44 | auto first = results[0]; |
| 45 | auto lmk = session->GetFaceDenseLandmark(first); |
| 46 | std::cout << "lmk: " << lmk.size() << std::endl; |
| 47 | for (size_t i = 0; i < lmk.size(); i++) { |
| 48 | image.DrawCircle(lmk[i].As<int>(), 5, inspirecv::Color::Red); |
| 49 | } |
| 50 | |
| 51 | inspirecv::TransformMatrix rotation_mode_affine = process.GetAffineMatrix(); |
| 52 | |
| 53 | std::vector<inspirecv::Point2f> stand_lmk = ApplyTransformToPoints(lmk, rotation_mode_affine.GetInverse()); |
| 54 | |
| 55 | // Use total lmk |
| 56 | auto rect = inspirecv::MinBoundingRect(stand_lmk); |
| 57 | auto rect_pts = rect.As<float>().ToFourVertices(); |
| 58 | std::vector<inspirecv::Point2f> dst_pts = {{0, 0}, {112, 0}, {112, 112}, {0, 112}}; |
| 59 | std::vector<inspirecv::Point2f> camera_pts = ApplyTransformToPoints(rect_pts, rotation_mode_affine); |
| 60 | |
| 61 | auto affine = inspirecv::SimilarityTransformEstimate(camera_pts, dst_pts); |
| 62 | auto image_affine = process.ExecuteImageAffineProcessing(affine, 112, 112); |
| 63 | image_affine.Write("affine.jpg"); |
| 64 | |
| 65 | // image.DrawRect(rect.As<int>(), inspirecv::Color::Red); |
| 66 | // image.Write("lmk.jpg"); |
nothing calls this directly
no test coverage detected