133 lines
3.3 KiB
C++
133 lines
3.3 KiB
C++
// sdk_test_liveness_ir.cpp : 定义控制台应用程序的入口点。
|
|
//
|
|
|
|
#include "stdafx.h"
|
|
#include "Inc/DeepCamFaceApi.h"
|
|
#include "Inc/TimeCount.h"
|
|
int PY = 50;
|
|
int PX = 50;
|
|
|
|
void test1()
|
|
{
|
|
cv::VideoCapture camera_ir(0);
|
|
cv::VideoCapture camera_rgb(2);
|
|
if (!camera_rgb.isOpened())
|
|
return;
|
|
if (!camera_ir.isOpened())
|
|
return;
|
|
while (true)
|
|
{
|
|
cv::Mat img_rgb, img_ir;
|
|
camera_rgb >> img_rgb;
|
|
camera_ir >> img_ir;
|
|
if (!img_rgb.empty() && !img_ir.empty())
|
|
{
|
|
std::vector<FaceInfo> face_infos;
|
|
{
|
|
USE_TIME t("FaceDetect ==> ");
|
|
DeepCamFaceDetect(img_ir, face_infos);
|
|
}
|
|
|
|
if (face_infos.size() > 0)
|
|
{
|
|
float score = 0.f;
|
|
|
|
{
|
|
USE_TIME t("Liveness IR => ");
|
|
DeepCamFaceLivenesIr(img_ir, face_infos[0].x1, face_infos[0].y1,
|
|
face_infos[0].x2, face_infos[0].y2, 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.8)
|
|
{
|
|
color = cv::Scalar(0, 255, 0);
|
|
txt = "Living";
|
|
}
|
|
cv::rectangle(img_rgb, cv::Rect(face_infos[0].x1, face_infos[0].y1, face_infos[0].GetWidth(), face_infos[0].GetHeight()), color, 2);
|
|
cv::putText(img_rgb, txt, cv::Point(10, 45), 2, 2, color, 2);
|
|
cv::rectangle(img_ir, cv::Rect(face_infos[0].x1, face_infos[0].y1, face_infos[0].GetWidth(), face_infos[0].GetHeight()), color, 2);
|
|
cv::putText(img_ir, txt, cv::Point(10, 45), 2, 2, color, 2);
|
|
}
|
|
cv::imshow("RGB", img_rgb);
|
|
cv::imshow("IR", img_ir);
|
|
cv::waitKey(1);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
void test2()
|
|
{
|
|
cv::VideoCapture camera_ir(0);
|
|
cv::VideoCapture camera_rgb(1);
|
|
if (!camera_rgb.isOpened())
|
|
return;
|
|
if (!camera_ir.isOpened())
|
|
return;
|
|
while (true)
|
|
{
|
|
cv::Mat img_rgb, img_ir;
|
|
camera_rgb >> img_rgb;
|
|
camera_ir >> img_ir;
|
|
if (!img_rgb.empty() && !img_ir.empty())
|
|
{
|
|
int face_num = 0;
|
|
{
|
|
USE_TIME t("FaceDetect ==> ");
|
|
face_num = DeepCamFaceDetectStd(img_ir.data, img_ir.cols, img_ir.rows, PIXEL_BGR);
|
|
}
|
|
|
|
if (face_num > 0)
|
|
{
|
|
float score = 0.f;
|
|
|
|
{
|
|
USE_TIME t("Liveness IR => ");
|
|
DeepCamFaceLivenesIrStd(0,score);
|
|
}
|
|
|
|
std::cout << "Liveness IR ==> " << 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_ir, txt, cv::Point(10, 45), 2, 2, color, 2);
|
|
cv::putText(img_rgb, txt, cv::Point(10, 45), 2, 2, color, 2);
|
|
|
|
|
|
float face_rect[4] = { 0.f };
|
|
DeepCamGetFaceRectStd(0, face_rect);
|
|
cv::rectangle(img_rgb, cv::Rect(face_rect[0], face_rect[1], face_rect[2] - face_rect[0], face_rect[3] - face_rect[1]), color, 2);
|
|
cv::rectangle(img_ir, 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_ir, cv::Point(face_landmark[i * 2], face_landmark[i * 2 + 1]), 1, cv::Scalar(0, 0, 255), 2);
|
|
cv::circle(img_rgb, cv::Point(face_landmark[i * 2], face_landmark[i * 2 + 1]), 1, cv::Scalar(0, 0, 255), 2);
|
|
}
|
|
}
|
|
cv::imshow("RGB", img_rgb);
|
|
cv::imshow("IR", img_ir);
|
|
cv::waitKey(1);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
int main()
|
|
{
|
|
test2();
|
|
return 0;
|
|
}
|
|
|