Video output bug fix.

This commit is contained in:
Tadas Baltrusaitis 2017-11-05 08:24:42 +00:00
parent c80016fc0c
commit db1fef46eb

View file

@ -232,7 +232,7 @@ int main (int argc, char **argv)
FaceAnalysis::FaceAnalyserParameters face_analysis_params(arguments); FaceAnalysis::FaceAnalyserParameters face_analysis_params(arguments);
FaceAnalysis::FaceAnalyser face_analyser(face_analysis_params); FaceAnalysis::FaceAnalyser face_analyser(face_analysis_params);
while(!done) // this is not a for loop as we might also be reading from a webcam while (!done) // this is not a for loop as we might also be reading from a webcam
{ {
string current_file; string current_file;
@ -246,10 +246,10 @@ int main (int argc, char **argv)
double fps_vid_in = -1.0; double fps_vid_in = -1.0;
// TODO this should be moved to a SequenceCapture class // TODO this should be moved to a SequenceCapture class
if(video_input) if (video_input)
{ {
// We might specify multiple video files as arguments // We might specify multiple video files as arguments
if(input_files.size() > 0) if (input_files.size() > 0)
{ {
f_n++; f_n++;
current_file = input_files[f_n]; current_file = input_files[f_n];
@ -260,10 +260,10 @@ int main (int argc, char **argv)
f_n = 0; f_n = 0;
} }
// Do some grabbing // Do some grabbing
if( current_file.size() > 0 ) if (current_file.size() > 0)
{ {
INFO_STREAM( "Attempting to read from file: " << current_file ); INFO_STREAM("Attempting to read from file: " << current_file);
video_capture = cv::VideoCapture( current_file ); video_capture = cv::VideoCapture(current_file);
total_frames = (int)video_capture.get(CV_CAP_PROP_FRAME_COUNT); total_frames = (int)video_capture.get(CV_CAP_PROP_FRAME_COUNT);
fps_vid_in = video_capture.get(CV_CAP_PROP_FPS); fps_vid_in = video_capture.get(CV_CAP_PROP_FPS);
@ -291,14 +291,14 @@ int main (int argc, char **argv)
{ {
f_n++; f_n++;
curr_img++; curr_img++;
if(!input_image_files[f_n].empty()) if (!input_image_files[f_n].empty())
{ {
string curr_img_file = input_image_files[f_n][curr_img]; string curr_img_file = input_image_files[f_n][curr_img];
captured_image = cv::imread(curr_img_file, -1); captured_image = cv::imread(curr_img_file, -1);
} }
else else
{ {
FATAL_STREAM( "No .jpg or .png images in a specified drectory, exiting" ); FATAL_STREAM("No .jpg or .png images in a specified drectory, exiting");
return 1; return 1;
} }
@ -307,7 +307,7 @@ int main (int argc, char **argv)
} }
// If optical centers are not defined just use center of image // If optical centers are not defined just use center of image
if(cx_undefined) if (cx_undefined)
{ {
cx = captured_image.cols / 2.0f; cx = captured_image.cols / 2.0f;
cy = captured_image.rows / 2.0f; cy = captured_image.rows / 2.0f;
@ -333,8 +333,8 @@ int main (int argc, char **argv)
// Timestamp in seconds of current processing // Timestamp in seconds of current processing
double time_stamp = 0; double time_stamp = 0;
INFO_STREAM( "Starting tracking"); INFO_STREAM("Starting tracking");
while(!captured_image.empty()) while (!captured_image.empty())
{ {
// Grab the timestamp first // Grab the timestamp first
@ -351,7 +351,7 @@ int main (int argc, char **argv)
// Reading the images // Reading the images
cv::Mat_<uchar> grayscale_image; cv::Mat_<uchar> grayscale_image;
if(captured_image.channels() == 3) if (captured_image.channels() == 3)
{ {
cvtColor(captured_image, grayscale_image, CV_BGR2GRAY); cvtColor(captured_image, grayscale_image, CV_BGR2GRAY);
} }
@ -363,7 +363,7 @@ int main (int argc, char **argv)
// The actual facial landmark detection / tracking // The actual facial landmark detection / tracking
bool detection_success; bool detection_success;
if(video_input || images_as_video) if (video_input || images_as_video)
{ {
detection_success = LandmarkDetector::DetectLandmarksInVideo(grayscale_image, face_model, det_parameters); detection_success = LandmarkDetector::DetectLandmarksInVideo(grayscale_image, face_model, det_parameters);
} }
@ -390,20 +390,20 @@ int main (int argc, char **argv)
int num_hog_rows = 0, num_hog_cols = 0; int num_hog_rows = 0, num_hog_cols = 0;
// As this can be expensive only compute it if needed by output or visualization // As this can be expensive only compute it if needed by output or visualization
if(recording_params.outputAlignedFaces() || recording_params.outputHOG() || recording_params.outputAUs() || visualize_align || visualize_hog) if (recording_params.outputAlignedFaces() || recording_params.outputHOG() || recording_params.outputAUs() || visualize_align || visualize_hog)
{ {
face_analyser.AddNextFrame(captured_image, face_model.detected_landmarks, face_model.detection_success, time_stamp, false, !det_parameters.quiet_mode); face_analyser.AddNextFrame(captured_image, face_model.detected_landmarks, face_model.detection_success, time_stamp, false, !det_parameters.quiet_mode);
face_analyser.GetLatestAlignedFace(sim_warped_img); face_analyser.GetLatestAlignedFace(sim_warped_img);
if(!det_parameters.quiet_mode && visualize_align) if (!det_parameters.quiet_mode && visualize_align)
{ {
cv::imshow("sim_warp", sim_warped_img); cv::imshow("sim_warp", sim_warped_img);
} }
if(recording_params.outputHOG() || (visualize_hog && !det_parameters.quiet_mode)) if (recording_params.outputHOG() || (visualize_hog && !det_parameters.quiet_mode))
{ {
face_analyser.GetLatestHOG(hog_descriptor, num_hog_rows, num_hog_cols); face_analyser.GetLatestHOG(hog_descriptor, num_hog_rows, num_hog_cols);
if(visualize_hog && !det_parameters.quiet_mode) if (visualize_hog && !det_parameters.quiet_mode)
{ {
cv::Mat_<double> hog_descriptor_vis; cv::Mat_<double> hog_descriptor_vis;
FaceAnalysis::Visualise_FHOG(hog_descriptor, num_hog_rows, num_hog_cols, hog_descriptor_vis); FaceAnalysis::Visualise_FHOG(hog_descriptor, num_hog_rows, num_hog_cols, hog_descriptor_vis);
@ -440,7 +440,7 @@ int main (int argc, char **argv)
//} //}
// Visualising the tracker, TODO this should be in utility // Visualising the tracker, TODO this should be in utility
if(visualize_track && !det_parameters.quiet_mode) if (recording_params.outputTrackedVideo() || (visualize_track && !det_parameters.quiet_mode))
{ {
visualise_tracking(captured_image, face_model, det_parameters, gazeDirection0, gazeDirection1, frame_count, fx, fy, cx, cy); visualise_tracking(captured_image, face_model, det_parameters, gazeDirection0, gazeDirection1, frame_count, fx, fy, cx, cy);
} }