113 lines
2.4 KiB
C++
113 lines
2.4 KiB
C++
// sdk_test_liveness_rgb.cpp : 定义控制台应用程序的入口点。
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "Inc/DeepCamFaceApi.h"
|
|
#include "Inc/TimeCount.h"
|
|
|
|
void test_api()
|
|
{
|
|
cv::VideoCapture camera1(1);
|
|
if (!camera1.isOpened())
|
|
return;
|
|
while (true)
|
|
{
|
|
cv::Mat img;
|
|
camera1 >> img;
|
|
if (!img.empty())
|
|
{
|
|
std::vector<FaceInfo> face_infos;
|
|
{
|
|
USE_TIME t("FaceDetect ==> ");
|
|
//DeepCamFaceDetectStd(img.data, img.cols, img.rows, PIXEL_BGR);
|
|
DeepCamFaceDetect(img, face_infos);
|
|
}
|
|
|
|
if (face_infos.size() > 0)
|
|
{
|
|
float score = 0.f;
|
|
|
|
{
|
|
USE_TIME t("Liveness RGB => ");
|
|
DeepCamFaceLivenessRgb(img, face_infos[0].landmarks, score);
|
|
}
|
|
|
|
//std::cout << "Liveness RGB ==> " << score << std::endl;
|
|
cv::Scalar color(0, 0, 255);
|
|
std::string txt = "Non-living";
|
|
if (score > 0.9)
|
|
{
|
|
color = cv::Scalar(0, 255, 0);
|
|
txt = "Living";
|
|
}
|
|
cv::rectangle(img, cv::Rect(face_infos[0].x1, face_infos[0].y1, face_infos[0].GetWidth(), face_infos[0].GetHeight()),
|
|
color, 2);
|
|
cv::putText(img, txt, cv::Point(10, 45), 2, 2, color, 2);
|
|
}
|
|
}
|
|
cv::imshow("LivenessRGB", img);
|
|
cv::waitKey(1);
|
|
}
|
|
}
|
|
|
|
void test_std_api()
|
|
{
|
|
cv::VideoCapture camera1(1);
|
|
if (!camera1.isOpened())
|
|
return;
|
|
while (true)
|
|
{
|
|
cv::Mat img;
|
|
camera1 >> img;
|
|
if (!img.empty())
|
|
{
|
|
int face_num = 0;
|
|
{
|
|
USE_TIME t("FaceDetect ==> ");
|
|
face_num = DeepCamFaceDetectStd(img.data, img.cols, img.rows, PIXEL_BGR);
|
|
}
|
|
|
|
if (face_num > 0)
|
|
{
|
|
float score = 0.f;
|
|
|
|
{
|
|
USE_TIME t("Liveness RGB => ");
|
|
DeepCamFaceLivenessRgbStd(0, score);
|
|
}
|
|
|
|
std::cout << "Liveness RGB ==> " << score << std::endl;
|
|
cv::Scalar color(0, 0, 255);
|
|
std::string txt = "Non-living";
|
|
if (score > 0.9)
|
|
{
|
|
color = cv::Scalar(0, 255, 0);
|
|
txt = "Living";
|
|
}
|
|
cv::putText(img, txt, cv::Point(10, 45), 2, 2, color, 2);
|
|
|
|
float face_rect[4] = { 0.f };
|
|
DeepCamGetFaceRectStd(0, face_rect);
|
|
cv::rectangle(img, cv::Rect(face_rect[0], face_rect[1], face_rect[2] - face_rect[0], face_rect[3] - face_rect[1]),color, 2);
|
|
|
|
float face_landmark[10] = { 0.f };
|
|
DeepCamGetFaceLandmarkStd(face_num, face_landmark);
|
|
for (int i = 0; i < 5; i++)
|
|
{
|
|
cv::circle(img, cv::Point(face_landmark[i * 2], face_landmark[i * 2 + 1]), 1, cv::Scalar(0, 0, 255), 2);
|
|
}
|
|
}
|
|
}
|
|
cv::imshow("LivenessRGB", img);
|
|
cv::waitKey(1);
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
//test_std_api();
|
|
test_api();
|
|
return 0;
|
|
}
|
|
|