資源簡介
基于opencv3.4以上版本,VS新建工程配置好opencv,修改代碼中路徑為自己的路徑即可

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#include?“windows.h“
#include?
using?namespace?std;
using?namespace?cv;
using?namespace?cv::dnn;
#define?SRC_PATH??“D:\\Edu_online\\image_for_test“
#define?DST_PATH??“D:\\Edu_online\\image_for_test_res“
#define?LONG_NAME_LEN?1024
const?size_t?inWidth?=?900;
const?size_t?inHeight?=?900;
const?double?inScaleFactor?=?1.0;
const?Scalar?meanVal(104.0?177.0?123.0);
void?find_folder_path(char?path[]?vector??*path_tree?int?level?=?0)
{
char?find_path[LONG_NAME_LEN];
sprintf_s(find_path?“%s\\*“?path);
WIN32_FIND_DATA?FindFileData;
HANDLE?hFind;
bool?bContinue?=?true;
hFind?=?FindFirstFile(find_path?&FindFileData);
if?(hFind?==?INVALID_HANDLE_VALUE)
return;
while?(bContinue)
{
if?(strcmp(FindFileData.cFileName?“..“)?&&?strcmp(FindFileData.cFileName?“.“))
{
if?(FindFileData.dwFileAttributes?==?FILE_ATTRIBUTE_DIRECTORY)
{?
sprintf_s(find_path?“%s\\%s“?path?FindFileData.cFileName);
path_tree->push_back(find_path);
find_folder_path(find_path?path_tree?level?+?1);
}
}
bContinue?=?FindNextFile(hFind?&FindFileData);
}
}
int?main(int?argc?char**?argv)
{?
//?step1?讀取路徑下圖片使用
vector??path_tree;
find_folder_path(SRC_PATH?&path_tree);
path_tree.push_back(SRC_PATH);
int?path_num?=?0;
//?step2?檢測需要使用
String?modelConfiguration?=?“./face_detector/deploy.prototxt“;
String?modelBinary?=?“./face_detector/res10_300x300_ssd_iter_140000.caffemodel“;
//!?[Initialize?network]
dnn::Net?net?=?readNetFromCaffe(modelConfiguration?modelBinary);
if?(net.empty())
????{
????????cerr?<“Can‘t?load?network?by?using?the?following?files:?“?<????????cerr?<“prototxt:???“?<????????cerr?<“caffemodel:?“?<????????cerr?<“Models?are?available?here:“?<????????cerr?<“/samples/dnn/face_detector“?<????????cerr?<“or?here:“?<????????cerr?<“https://github.com/opencv/opencv/tree/master/samples/dnn/face_detector“?<????????exit(-1);
????}
//if?(parser.get(“opencl“))
{
//net.setPreferableTarget(DNN_TARGET_OPENCL);
}
char?eye_pos_path[LONG_NAME_LEN];
for?(path_num?=?0;?path_num? {
//?查找路徑下所有圖片
memset(eye_pos_path?0?LONG_NAME_LEN*sizeof(char));
sprintf_s(eye_pos_path?“%s“?path_tree.at(path_num).c_str());
printf(“\n%s?...\n“?path_tree.at(path_num).c_str());
Mat?inputBlob;
char?find_name[1024]?=?““;
sprintf_s(find_name?“%s\\*.jpg“?eye_pos_path);?//?原圖jpg格式
_finddata_t?file_info;
intptr_t?????????f_handle?=?_findfirst(find_name?&file_info);
if?(f_handle?!=?-1)
{
do
{
//?讀取原圖
char?org_
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????28103??2018-05-13?11:58??代碼+模型+網絡\deploy.prototxt
?????文件???????6462??2018-05-13?17:03??代碼+模型+網絡\main.cpp
?????文件???10666211??2018-01-22?01:22??代碼+模型+網絡\res10_300x300_ssd_iter_140000.caffemodel
?????目錄??????????0??2018-05-13?17:16??代碼+模型+網絡
-----------?---------??----------?-----??----
?????????????10700776????????????????????4
評論
共有 條評論