概述
这里是运行速度 (i7-6700)
https://github.com/ShiqiYu/libfacedetection
首先下载代码压缩包,解压
打开src
将这几个文件复制到你的项目文件夹中
在项目中以添加现有项的方式将这四个文件添加到项目中
右键项目打开项目属性,并选择Release – x64
首先配置opencv,请自行查阅其他人的博客,有很多人都有详细的配置步骤,这里跳过
选择c/c++ 优化选择使速度最大化(/O2)
所有选项OpenMp支持 --是
在facedetectcnn.h下对代码进行修改
修改之后,在自己的项目下创建新的cpp把以下代码复制进去(于老师给的例子,摄像头检测人脸,并把调用摄像头的代码进行了一点点更改)
/*
By downloading, copying, installing or using the software you agree to this license.
If you do not agree to this license, do not download, install,
copy or use the software.
License Agreement For libfacedetection
(3-clause BSD License)
Copyright (c) 2018-2020, Shiqi Yu, all rights reserved.
shiqi.yu@gmail.com
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the names of the copyright holders nor the names of the contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and
any express or implied warranties, including, but not limited to, the implied
warranties of merchantability and fitness for a particular purpose are disclaimed.
In no event shall copyright holders or contributors be liable for any direct,
indirect, incidental, special, exemplary, or consequential damages
(including, but not limited to, procurement of substitute goods or services;
loss of use, data, or profits; or business interruption) however caused
and on any theory of liability, whether in contract, strict liability,
or tort (including negligence or otherwise) arising in any way out of
the use of this software, even if advised of the possibility of such damage.
*/
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "facedetectcnn.h"
//define the buffer size. Do not change the size!
#define DETECT_BUFFER_SIZE 0x20000
using namespace cv;
int main()
{
VideoCapture capture(0);
Mat face;
int * pResults = NULL;
//pBuffer is used in the detection functions.
//If you call functions in multiple threads, please create one buffer for each thread!
unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
if (!pBuffer)
{
fprintf(stderr, "Can not alloc buffer.n");
return -1;
}
Mat im;
if (!capture.isOpened())
{
puts("dont open video.");
system("pause");
return -1;
}
if (capture.isOpened())
{
while (true)
{
capture >> im;
//cout << "Image size: " << im.rows << "X" << im.cols << endl;
Mat image = im.clone();
///
// CNN face detection
// Best detection rate
//
//!!! The input image must be a BGR one (three-channel) instead of RGB
//!!! DO NOT RELEASE pResults !!!
TickMeter cvtm;
cvtm.start();
pResults = facedetect_cnn(pBuffer, (unsigned char*)(image.ptr(0)), image.cols, image.rows, (int)image.step);
cvtm.stop();
printf("time = %gmsn", cvtm.getTimeMilli());
printf("%d faces detected.n", (pResults ? *pResults : 0));
Mat result_image = image.clone();
//print the detection results
for (int i = 0; i < (pResults ? *pResults : 0); i++)
{
short * p = ((short*)(pResults + 1)) + 142 * i;
int confidence = p[0];
int x = p[1];
int y = p[2];
int w = p[3];
int h = p[4];
//show the score of the face. Its range is [0-100]
char sScore[256];
snprintf(sScore, 256, "%d", confidence);
cv::putText(result_image, sScore, cv::Point(x, y - 3), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 255, 0), 1);
//draw face rectangle
rectangle(result_image, Rect(x, y, w, h), Scalar(0, 255, 0), 2);
//draw five face landmarks in different colors
cv::circle(result_image, cv::Point(p[5], p[5 + 1]), 1, cv::Scalar(255, 0, 0), 2);
cv::circle(result_image, cv::Point(p[5 + 2], p[5 + 3]), 1, cv::Scalar(0, 0, 255), 2);
cv::circle(result_image, cv::Point(p[5 + 4], p[5 + 5]), 1, cv::Scalar(0, 255, 0), 2);
cv::circle(result_image, cv::Point(p[5 + 6], p[5 + 7]), 1, cv::Scalar(255, 0, 255), 2);
cv::circle(result_image, cv::Point(p[5 + 8], p[5 + 9]), 1, cv::Scalar(0, 255, 255), 2);
if (confidence == 99)
face = result_image(Rect(x, y, w, h));
//print the result
printf("face %d: confidence=%d, [%d, %d, %d, %d] (%d,%d) (%d,%d) (%d,%d) (%d,%d) (%d,%d)n",
i, confidence, x, y, w, h,
p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14]);
}
imshow("result", result_image);
if ((cv::waitKey(2) & 0xFF) == 'q')
break;
}
}
//release the buffer
free(pBuffer);
return 0;
}
最后
以上就是辛勤发带为你收集整理的于仕琪libfacedetection WIN10 VS2015的全部内容,希望文章能够帮你解决于仕琪libfacedetection WIN10 VS2015所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复