Skip to content

Commit

Permalink
Renamed deprecated opencv constants
Browse files Browse the repository at this point in the history
  • Loading branch information
severin-lemaignan committed Nov 17, 2021
1 parent 2bd544b commit 56fa798
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 86 deletions.
95 changes: 41 additions & 54 deletions tools/estimate_head_direction.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#include <opencv2/opencv.hpp>

#include <iostream>
#include <iomanip>

#include <boost/program_options.hpp>

#include "LinearMath/Matrix3x3.h"
#include <iomanip>
#include <iostream>
#include <opencv2/opencv.hpp>

#include "../src/head_pose_estimation.hpp"
#include "LinearMath/Matrix3x3.h"

#define STR_EXPAND(tok) #tok
#define STR(tok) STR_EXPAND(tok)
Expand All @@ -16,13 +13,9 @@ using namespace std;
using namespace cv;
namespace po = boost::program_options;

inline double todeg(double rad) {
return rad * 180 / M_PI;
}

inline double todeg(double rad) { return rad * 180 / M_PI; }

int main(int argc, char **argv)
{
int main(int argc, char **argv) {
Mat frame;
bool show_frame = false;
bool use_camera = false;
Expand All @@ -31,23 +24,20 @@ int main(int argc, char **argv)
p.add("image", 1);

po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produce help message")
("version,v", "shows version and exits")
("show,s", "display the image with gaze estimation")
("model", po::value<string>(), "dlib's trained face model")
("image", po::value<string>(), "image to process (png, jpg)")
;
desc.add_options()("help,h", "produce help message")(
"version,v", "shows version and exits")(
"show,s", "display the image with gaze estimation")(
"model", po::value<string>(), "dlib's trained face model")(
"image", po::value<string>(), "image to process (png, jpg)");

po::variables_map vm;
po::store(po::command_line_parser(argc, argv)
.options(desc)
.positional(p)
.run(), vm);
po::store(
po::command_line_parser(argc, argv).options(desc).positional(p).run(),
vm);
po::notify(vm);

if (vm.count("help")) {
cout << argv[0] << " " << STR(GAZR_VERSION) << "\n\n" << desc << "\n";
cout << argv[0] << " " << STR(GAZR_VERSION) << "\n\n" << desc << "\n";
return 1;
}

Expand Down Expand Up @@ -78,13 +68,13 @@ int main(int argc, char **argv)
video_in = VideoCapture(0);

// adjust for your webcam!
video_in.set(CV_CAP_PROP_FRAME_WIDTH, 640);
video_in.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
video_in.set(cv::CAP_PROP_FRAME_WIDTH, 640);
video_in.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
estimator.focalLength = 500;
estimator.opticalCenterX = 320;
estimator.opticalCenterY = 240;

if(!video_in.isOpened()) {
if (!video_in.isOpened()) {
cerr << "Couldn't open camera" << endl;
return 1;
}
Expand All @@ -94,46 +84,40 @@ int main(int argc, char **argv)
auto image = vm["image"].as<string>();

#ifdef OPENCV3
frame = imread(image,IMREAD_COLOR);
frame = imread(image, IMREAD_COLOR);
#else
frame = imread(image,CV_LOAD_IMAGE_COLOR);
frame = imread(image, CV_LOAD_IMAGE_COLOR);
#endif

resize(frame, frame, Size(0,0), 0.2,0.2);
resize(frame, frame, Size(0, 0), 0.2, 0.2);

estimator.focalLength = 85.0 / 22.3 * frame.size().width;
}

while(true) {
if(use_camera) {
while (true) {
if (use_camera) {
auto ok = video_in.read(frame);
if (!ok) break;
}


auto all_features = estimator.update(frame);


auto poses = estimator.poses();

int i = 0;
cout << "{";

for(auto pose : poses) {



for (auto pose : poses) {
pose = pose.inv();

double raw_yaw, raw_pitch, raw_roll;
tf::Matrix3x3 mrot(
pose(0,0), pose(0,1), pose(0,2),
pose(1,0), pose(1,1), pose(1,2),
pose(2,0), pose(2,1), pose(2,2));
tf::Matrix3x3 mrot(pose(0, 0), pose(0, 1), pose(0, 2), pose(1, 0),
pose(1, 1), pose(1, 2), pose(2, 0), pose(2, 1),
pose(2, 2));
mrot.getRPY(raw_roll, raw_pitch, raw_yaw);

raw_roll = raw_roll - M_PI/2;
raw_yaw = raw_yaw + M_PI/2;
raw_roll = raw_roll - M_PI / 2;
raw_yaw = raw_yaw + M_PI / 2;

double yaw, pitch, roll;

Expand All @@ -142,25 +126,28 @@ int main(int argc, char **argv)
pitch = -raw_roll;

cout << "\"face_" << i << "\":";
cout << setprecision(1) << fixed << "{\"yaw\":" << todeg(yaw) << ", \"pitch\":" << todeg(pitch) << ", \"roll\":" << todeg(roll) << ",";
cout << setprecision(4) << fixed << "\"x\":" << pose(0,3) << ", \"y\":" << pose(1,3) << ", \"z\":" << pose(2,3) << "},";
cout << setprecision(1) << fixed << "{\"yaw\":" << todeg(yaw)
<< ", \"pitch\":" << todeg(pitch)
<< ", \"roll\":" << todeg(roll) << ",";
cout << setprecision(4) << fixed << "\"x\":" << pose(0, 3)
<< ", \"y\":" << pose(1, 3) << ", \"z\":" << pose(2, 3)
<< "},";

i++;
}
cout << "}\n" << flush;

if (show_frame) {
imshow("headpose", estimator.drawDetections(frame, all_features, poses));
if(use_camera) {
imshow("headpose",
estimator.drawDetections(frame, all_features, poses));
if (use_camera) {
waitKey(10);
}
else {
while(waitKey(10) != 1048603) {}
} else {
while (waitKey(10) != 1048603) {
}
break;
}
}
}

}


54 changes: 22 additions & 32 deletions tools/show_head_pose.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <iomanip>

#include <boost/program_options.hpp>
#include <iomanip>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>

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

Expand All @@ -13,12 +12,9 @@ using namespace std;
using namespace cv;
namespace po = boost::program_options;

inline double todeg(double rad) {
return rad * 180 / M_PI;
}
inline double todeg(double rad) { return rad * 180 / M_PI; }

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

namedWindow("headpose");
Expand All @@ -29,18 +25,16 @@ int main(int argc, char **argv)
p.add("video", 1);

po::options_description desc("Allowed options");
desc.add_options()
("help,h", "produces help message")
("version,v", "shows version and exits")
("model", po::value<string>(), "dlib's trained face model")
("video", po::value<string>(), "video to process. If omitted, uses the first webcam")
;
desc.add_options()("help,h", "produces help message")(
"version,v", "shows version and exits")("model", po::value<string>(),
"dlib's trained face model")(
"video", po::value<string>(),
"video to process. If omitted, uses the first webcam");

po::variables_map vm;
po::store(po::command_line_parser(argc, argv)
.options(desc)
.positional(p)
.run(), vm);
po::store(
po::command_line_parser(argc, argv).options(desc).positional(p).run(),
vm);
po::notify(vm);

if (vm.count("help")) {
Expand All @@ -61,31 +55,28 @@ int main(int argc, char **argv)

auto estimator = HeadPoseEstimation(vm["model"].as<string>());


// Configure the video capture
// ===========================

VideoCapture video_in;

if (vm.count("video") == 0) {
video_in = VideoCapture(0);
video_in.set(CV_CAP_PROP_FRAME_WIDTH, 640);
video_in.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
}
else {
video_in.set(cv::CAP_PROP_FRAME_WIDTH, 640);
video_in.set(cv::CAP_PROP_FRAME_HEIGHT, 480);
} else {
video_in = VideoCapture(vm["video"].as<string>());
}

// adjust for your webcam!
estimator.focalLength = 500;

if(!video_in.isOpened()) {
if (!video_in.isOpened()) {
cerr << "Couldn't open camera/video file" << endl;
return 1;
}


while(true) {
while (true) {
auto ok = video_in.read(frame);
if (!ok) break;

Expand All @@ -95,13 +86,12 @@ int main(int argc, char **argv)
auto poses = estimator.poses();

auto t_end = getTickCount();
cout << "Processing time for this frame: " << (t_end-t_start) / getTickFrequency() * 1000. << "ms" << endl;
cout << "Processing time for this frame: "
<< (t_end - t_start) / getTickFrequency() * 1000. << "ms" << endl;

imshow("headpose", estimator.drawDetections(frame, all_features, poses));
imshow("headpose",
estimator.drawDetections(frame, all_features, poses));
if (waitKey(10) >= 0) break;

}
}



0 comments on commit 56fa798

Please sign in to comment.