///////////////////////////////////////////////////////////////////////////////////////////////////////
/// DemoTracker.cpp
///
/// Description:
/// This program shows you how to use FaceAlignment class in tracking facial landmarks in a video or realtime.
/// There are two modes: VIDEO, REALTIME.
/// In the VIDEO mode, the program reads input from a video and perform tracking.
/// In the REALTIME mode, the program reads input from the first camera it finds and perform tracking.
/// Note that tracking is performed on the largest face found. The face is detected through OpenCV.
/// In this version, we add head pose estimation.
///
/// Dependencies: None. OpenCV DLLs and include folders are copied.
///
/// Author: Xuehan Xiong, xiong828@gmail.com
///
/// Creation Date: 1/24/2014
///
/// Version: 1.2
///
/// Citation:
/// Xuehan Xiong, Fernando de la Torre, Supervised Descent Method and Its Application to Face Alignment. CVPR, 2013
///////////////////////////////////////////////////////////////////////////////////////////////////////
#include <opencv2/core/core.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <time.h>
#include <Windows.h>
#include <intraface/FaceAlignment.h>
#include <intraface/XXDescriptor.h>
using namespace std;
using namespace cv;
bool compareRect(cv::Rect r1, cv::Rect r2) { return r1.height < r2.height; }
// 2 modes: REALTIME,VIDEO
#define REALTIME
void drawPose(cv::Mat& img, const cv::Mat& rot, float lineL)
{
int loc[2] = {70, 70};
int thickness = 2;
int lineType = 8;
cv::Mat P = (cv::Mat_<float>(3,4) <<
0, lineL, 0, 0,
0, 0, -lineL, 0,
0, 0, 0, -lineL);
P = rot.rowRange(0,2)*P;
P.row(0) += loc[0];
P.row(1) += loc[1];
cv::Point p0(P.at<float>(0,0),P.at<float>(1,0));
line(img, p0, cv::Point(P.at<float>(0,1),P.at<float>(1,1)), cv::Scalar( 255, 0, 0 ), thickness, lineType);
line(img, p0, cv::Point(P.at<float>(0,2),P.at<float>(1,2)), cv::Scalar( 0, 255, 0 ), thickness, lineType);
line(img, p0, cv::Point(P.at<float>(0,3),P.at<float>(1,3)), cv::Scalar( 0, 0, 255 ), thickness, lineType);
//printf("%f %f %f\n", rot.at<float>(0, 0), rot.at<float>(0, 1), rot.at<float>(0, 2));
//printf("%f %f %f\n", rot.at<float>(1, 0), rot.at<float>(1, 1), rot.at<float>(1, 2));
//printf("%f %f %f\n", rot.at<float>(2, 0), rot.at<float>(2, 1), rot.at<float>(2, 2));
Vec3d eav;
Mat tmp,tmp1,tmp2,tmp3,tmp4,tmp5;
double _pm[12] = {rot.at<float>(0, 0), rot.at<float>(0, 1),rot.at<float>(0, 2), 0,
rot.at<float>(1, 0), rot.at<float>(1, 1),rot.at<float>(1, 2),0,
rot.at<float>(2, 0),rot.at<float>(2, 1),rot.at<float>(2, 2),0};
decomposeProjectionMatrix(Mat(3,4,CV_64FC1,_pm),tmp,tmp1,tmp2,tmp3,tmp4,tmp5,eav);
stringstream ss;
ss << eav[0];
string txt = "Pitch: " + ss.str();
putText(img, txt, Point(60, 20), 0.5,0.5,Scalar(255,255,255));
stringstream ss1;
ss1 << eav[1];
string txt1 = "Yaw: " + ss1.str();
putText(img, txt1, Point(60, 40), 0.5,0.5,Scalar(255,255,255));
stringstream ss2;
ss2 << eav[2];
string txt2 = "Roll: " + ss2.str();
putText(img, txt2, Point(60, 60), 0.5,0.5,Scalar(255,255,255));
}
int main()
{
char detectionModel[] = "../models/DetectionModel-v1.5.bin";
char trackingModel[] = "../models/DetectionModel-v1.5.bin";
string faceDetectionModel("../models/haarcascade_frontalface_alt2.xml");
// initialize a XXDescriptor object
INTRAFACE::XXDescriptor xxd(4);
// initialize a FaceAlignment object
INTRAFACE::FaceAlignment fa(detectionModel, detectionModel, &xxd);
if (!fa.Initialized()) {
cerr << "FaceAlignment cannot be initialized." << endl;
return -1;
}
// load OpenCV face detector model
cv::CascadeClassifier face_cascade;
if( !face_cascade.load( faceDetectionModel ) )
{
cerr << "Error loading face detection model." << endl;
return -1;
}
#ifdef REALTIME
// use the first camera it finds
cv::VideoCapture cap(0);
#endif
#ifdef VIDEO
string filename("../data/vid.wmv");
cv::VideoCapture cap(filename);
#endif
if(!cap.isOpened())
return -1;
int key = 0;
bool isDetect = true;
bool eof = false;
float score, notFace = 0.3;
cv::Mat X,X0;
string winname("Demo IntraFace Tracker");
cv::namedWindow(winname);
while (key!=27) // Press Esc to quit
{
cv::Mat frame;
cap >> frame; // get a new frame from camera
//frame = cv::imread("xjp4.jpg");
if (frame.rows == 0 || frame.cols == 0)
break;
if (isDetect)
{
// face detection
vector<cv::Rect> faces;
face_cascade.detectMultiScale(frame, faces, 1.2, 2, 0, cv::Size(50, 50));
// if no face found, do nothing
if (faces.empty()) {
cv::imshow(winname,frame);
key = cv::waitKey(5);
continue ;
}
clock_t start_time1 = clock();
// facial feature detection on largest face found
if (fa.Detect(frame,*max_element(faces.begin(),faces.end(),compareRect),X0,score) != INTRAFACE::IF_OK)
break;
clock_t finish_time1 = clock();
double total_time = (double)(finish_time1-start_time1)/CLOCKS_PER_SEC;
std::cout<< "detect time: " << total_time*1000 << endl;
isDetect = false;
}
else
{
clock_t start_time1 = clock();
// facial feature tracking
if (fa.Track(frame,X0,X,score) != INTRAFACE::IF_OK)
break;
clock_t finish_time1 = clock();
double total_time = (double)(finish_time1-start_time1)/CLOCKS_PER_SEC;
std::cout<< "track time: " << total_time*1000 << endl;
X0 = X;
}
if (score < notFace) // detected face is not reliable
isDetect = true;
else
{
// plot facial landmarks
for (int i = 0 ; i < X0.cols ; i++)
cv::circle(frame,cv::Point((int)X0.at<float>(0,i), (int)X0.at<float>(1,i)), 1, cv::Scalar(0,255,0), -1);
// head pose estimation
INTRAFACE::HeadPose hp;
fa.EstimateHeadPose(X0,hp);
// plot head pose
drawPose(frame, hp.rot, 50);
}
printf("score %f\n", score);
cv::imshow(winname,frame);
key = cv::waitKey(5);
}
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
intraFace人脸对齐 (292个子文件)
TrackingModel-v1.10.bin 9.43MB
DetectionModel-v1.5.bin 9.43MB
DemoTracker.cpp 6KB
binary_model_file.cpp 5KB
DemoDetector.cpp 5KB
opencv_ffmpeg246_64.dll 8.79MB
opencv_ffmpeg246_64.dll 8.79MB
opencv_core246d.dll 4.95MB
opencv_imgproc246d.dll 4.6MB
opencv_highgui246d.dll 4.59MB
opencv_core246.dll 2.45MB
opencv_highgui246.dll 2.33MB
opencv_imgproc246.dll 2.14MB
opencv_objdetect246d.dll 2.11MB
opencv_calib3d246.dll 947KB
opencv_features2d246.dll 882KB
opencv_objdetect246.dll 825KB
opencv_flann246.dll 628KB
IntraFaceDLLd.dll 340KB
IntraFaceDLL.dll 81KB
IntraFaceTracker.exe 153KB
IntraFaceDetector.exe 128KB
IntraFaceTracker.exe 39KB
IntraFaceDetector.exe 18KB
IntraFaceDetector.vcxproj.filters 2KB
IntraFaceTracker.vcxproj.filters 2KB
ts_gtest.h 811KB
core_c.h 77KB
types_c.h 56KB
kmeans_index.h 34KB
imgproc_c.h 30KB
highgui_c.h 26KB
dist.h 25KB
hierarchical_clustering_index.h 21KB
autotuned_index.h 20KB
kdtree_single_index.h 20KB
kdtree_index.h 19KB
lsh_table.h 18KB
types_c.h 16KB
lsh_index.h 15KB
result_set.h 15KB
index_testing.h 11KB
any.h 7KB
hdf5.h 7KB
nn_index.h 6KB
allocator.h 6KB
composite_index.h 6KB
all_indices.h 6KB
saving.h 6KB
simplex_downhill.h 6KB
cap_ios.h 5KB
defines.h 5KB
dynamic_bitset.h 4KB
heap.h 4KB
logger.h 4KB
linear_index.h 4KB
random.h 4KB
FaceAlignment.h 4KB
cv.h 3KB
ground_truth.h 3KB
matrix.h 3KB
params.h 3KB
object_factory.h 3KB
cvaux.h 3KB
sampling.h 3KB
photo_c.h 3KB
cxcore.h 2KB
timer.h 2KB
ios.h 2KB
highgui.h 2KB
ml.h 2KB
cvwimage.h 2KB
general.h 2KB
config.h 2KB
XXDescriptor.h 1KB
Marcos.h 920B
binary_model_file.h 495B
dummy.h 251B
cxmisc.h 110B
color_detail.hpp 217KB
core.hpp 182KB
legacy.hpp 134KB
operations.hpp 126KB
gpu.hpp 108KB
ocl.hpp 81KB
mat.hpp 79KB
ml.hpp 77KB
features2d.hpp 62KB
imgproc.hpp 55KB
vec_math.hpp 49KB
contrib.hpp 38KB
calib3d.hpp 37KB
objdetect.hpp 36KB
internal.hpp 34KB
simd_functions.hpp 33KB
blobtrack.hpp 32KB
functional.hpp 31KB
compat.hpp 29KB
border_interpolate.hpp 24KB
retina.hpp 23KB
共 292 条
- 1
- 2
- 3
资源评论
- wangqiang0362018-03-01非常好!!
- 地下吉他手2018-04-13不知道好不好用,先评论
中本聪会编程
- 粉丝: 27
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 前端开发-什么是前端开发-关于前端开发的一些相关介绍
- Sora AI-关于文生视频的使用场景说明
- suno AI文生视频的相关教程和介绍使用
- 什么是后端开发-关于后端开发的一些小介绍分享
- Jurassic Pack Vol. II Dinosaurs 侏罗纪包卷恐龙二号Unity游戏模型资源unitypackage
- Jurassic Pack Vol. III Dinosaurs 侏罗纪包卷恐龙三号Unity游戏模型资源unitypackag
- Ultimate Seating Controller 终极座椅控制器Unity游戏开发插件资源unitypackage
- 什么是人工智能-关于人工智能的相关介绍说明
- Figma Converter for Unity适用Unity的Figma转换器Unity游戏开发插件unitypackage
- Creepy Animatronic Anims 令人毛骨悚然的电子动画Unity游戏动画插件资源unitypackage
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功