-
-
Save LitvinenkoIra/065cc5946bdbf54bbc6afb7c558b8e85 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <dlib/image_processing/frontal_face_detector.h> | |
#include <dlib/gui_widgets.h> | |
#include <dlib/image_io.h> | |
#include <iostream> | |
#include <string> | |
#include <sys/types.h> | |
#include <dirent.h> | |
#include <errno.h> | |
#include <vector> | |
#include <string> | |
#include <iostream> | |
#include <algorithm> | |
const std::string kSashaPath = "./Sasha/"; | |
const std::string kIraPath = "./Ira/"; | |
int getdir (std::string dir, std::vector<std::string> &files) { | |
using namespace std; | |
DIR *dp; | |
struct dirent *dirp; | |
if((dp = opendir(dir.c_str())) == NULL) { | |
cout << "Error(" << errno << ") opening " << dir << endl; | |
return errno; | |
} | |
while ((dirp = readdir(dp)) != NULL) { | |
std::string name = dirp->d_name; | |
if (name[0] != '.') { | |
files.push_back(string(dirp->d_name)); | |
} | |
} | |
closedir(dp); | |
return 0; | |
} | |
dlib::frontal_face_detector detector = dlib::get_frontal_face_detector(); | |
void process_image(std::string s) { | |
dlib::array2d<unsigned char> img; | |
dlib::load_image(img, s); | |
std::vector<dlib::rectangle> dets = detector(img); | |
std::cout << s << " " << dets.size() << std::endl; | |
std::vector<dlib::chip_details> details(dets.size()); | |
std::transform(dets.begin(), dets.end(), details.begin(), [](auto rect) {return dlib::chip_details(rect);}); | |
dlib::array<dlib::matrix<dlib::rgb_pixel>> crops; | |
dlib::extract_image_chips(img, details, crops); | |
for (auto face : crops) { | |
std::cout << s << " Proceed" << std::endl; | |
save_jpeg ( face, s + "_face.jpg"); | |
} | |
} | |
int main() { | |
std::vector<std::string> sasha_pics; | |
std::vector<std::string> ira_pics; | |
getdir(kSashaPath, sasha_pics); | |
getdir(kIraPath, ira_pics); | |
std::transform(sasha_pics.begin(), sasha_pics.end(), sasha_pics.begin(), [](std::string& val) {return kSashaPath + val;}); | |
std::transform(ira_pics.begin(), ira_pics.end(), ira_pics.begin(), [](std::string& val) {return kIraPath + val;}); | |
for(std::string s : sasha_pics) { | |
process_image(s); | |
} | |
for(std::string s : ira_pics) { | |
process_image(s); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment