Skip to content

Commit

Permalink
Added ability to run on multiple files at once
Browse files Browse the repository at this point in the history
  • Loading branch information
voletiv committed Nov 3, 2017
1 parent c473917 commit fef52c5
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ if(WITH_TOOLS)
add_executable(gazr_benchmark_head_pose_single_frame tools/benchmark_head_pose_estimation_single_frame.cpp)
target_link_libraries(gazr_benchmark_head_pose_single_frame gazr ${OpenCV_LIBRARIES})

add_executable(gazr_benchmark_head_pose_multiple_frames tools/benchmark_head_pose_estimation_multiple_frames.cpp)
target_link_libraries(gazr_benchmark_head_pose_multiple_frames gazr ${OpenCV_LIBRARIES})

add_executable(gazr_estimate_head_direction tools/estimate_head_direction.cpp)
target_link_libraries(gazr_estimate_head_direction gazr ${OpenCV_LIBRARIES} ${Boost_LIBRARIES})

Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ apt-get install libdlib-dev`

You also need OpenCV. On Ubuntu, `sudo apt-get install libopencv-dev`.

### Installation
### Installation - 1/2

The library uses a standard ``CMake`` workflow:

Expand All @@ -64,9 +64,24 @@ $ cmake ..
$ make
```

#### Example - show head pose

Run ``./gazr_show_head_pose ../share/shape_predictor_68_face_landmarks.dat`` to test
the library. You should get something very similar to the picture above.

#### Example - single frame

Run ``./gazr_benchmark_head_pose_single_frame ../share/shape_predictor_68_face_landmarks.dat frame.jpg``
to print the head pose detected in _frame.jpg_.

#### Example - multiple frames

Run ``./gazr_benchmark_head_pose_multiple_frames ../share/shape_predictor_68_face_landmarks.dat filenames.txt``
to print the head pose detected in each file listed in _filenames.txt_.


### Installation - 2/2

Finally, to install the library:

```
Expand Down
97 changes: 97 additions & 0 deletions tools/benchmark_head_pose_estimation_multiple_frames.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#define STR_EXPAND(tok) #tok
#define STR(tok) STR_EXPAND(tok)

#ifdef OPENCV3
#include <opencv2/imgcodecs.hpp>
#else
#include <opencv2/highgui/highgui.hpp>
#endif

#include <iostream>

#include "../src/head_pose_estimation.hpp"

using namespace std;
using namespace cv;

const static size_t NB_TESTS = 1; // number of time the detection is run, to get better average detection duration

std::vector<std::string> readFileToVector(const std::string& filename)
{
std::ifstream source;
source.open(filename);
std::vector<std::string> lines;
std::string line;
while (std::getline(source, line))
{
lines.push_back(line);
}
return lines;
}

int main(int argc, char **argv)
{
Mat frame;

if(argc < 3) {
cerr << argv[0] << " " << STR(GAZR_VERSION) << "\n\nUsage: "
<< endl << argv[0] << " model.dat filenames.txt" << endl;
return 1;
}


auto estimator = HeadPoseEstimation(argv[1]);
estimator.focalLength = 500;

// Read file
std::string frameFilesTxt(argv[2]);
std::vector<std::string> frameFileNames = readFileToVector(frameFilesTxt);

// cout << "Running " << NB_TESTS << " loops to get a good performance estimate..." << endl;

auto t_start = getTickCount();

for(auto frameFileName: frameFileNames) {

cout << "Estimating head pose on " << frameFileName << endl;
#ifdef OPENCV3
Mat img = imread(frameFileName, IMREAD_COLOR);
#else
Mat img = imread(frameFileName, CV_LOAD_IMAGE_COLOR);
#endif

auto nbfaces = 0;

for(size_t i = 0; i < NB_TESTS; i++) {
estimator.update(img);
}
// auto t_detection = getTickCount();

for(size_t i = 0; i < NB_TESTS; i++) {
auto poses = estimator.poses();
nbfaces += poses.size(); // this is completly artifical: the only purpose is to make sure the compiler does not optimize away estimator.poses()
}

// cout << "Found " << nbfaces/NB_TESTS << " faces" << endl;

auto poses = estimator.poses();
if (poses.size() == 1) {
for(auto pose : poses) {
cout << "Head pose: (" << pose(0,3) << ", " << pose(1,3) << ", " << pose(2,3) << ")" << endl;
}
}
// In case no face is detected
else {
cout << "Head pose: (-1, -1, -1)" << endl;
}

}

auto t_end = getTickCount();
// cout << "Face feature detection: " <<((t_detection-t_start) / NB_TESTS) /getTickFrequency() * 1000. << "ms;";
// cout << "Pose estimation: " <<((t_end-t_detection) / NB_TESTS) /getTickFrequency() * 1000. << "ms;";
cout << "Total time: " << (t_end-t_start) / getTickFrequency() * 1000. << "ms" << endl;

}


0 comments on commit fef52c5

Please sign in to comment.