#include #include "eye_cameras.h" #include "timer.h" #include //#include //#include // Step1: include the header. namespace eye_tracker { namespace fs = boost::filesystem; void record_eyecams_mono_interactive(){ const size_t kCcameraNums = 1; // Open and check cameras cv::Mat images[kCcameraNums]; EyeCamera eyecams[kCcameraNums] = { EyeCamera(0,true)}; std::string window_names[kCcameraNums] = { "Cam0" }; for (size_t cam = 0; cam < kCcameraNums; cam++){ // Check if the cameras are opened if (eyecams[cam].isOpened() == false){ std::cout << "Could not open the camera" << std::endl; return; } // Capture single frames to get image sizes; for (size_t cam = 0; cam < kCcameraNums; cam++){ eyecams[cam].fetchFrame(images[cam]); if (images[cam].empty()){ std::cout << "Could not capture an image" << std::endl; return; } } } // Save buffered images to files std::ostringstream ost_frame_id; const std::string kDir = "./tmp/"; const std::streamsize kStreamSize = 3; const char kPaddingChar = '0'; const std::string kImageFormat = "png"; cv::VideoWriter outputVideos[kCcameraNums]; for (size_t cam = 0; cam < kCcameraNums; cam++){ std::ostringstream ost_video_name; ost_video_name << kDir << "cam" << cam << ".avi"; outputVideos[cam].open(ost_video_name.str(), -1, 30, images[cam].size()); } // Capture and store images size_t frame_count = 0; timer timer0; timer0.pause(); bool run = true; while (run){ // while (frame_count> eyecams(kCcameraNums); // Image sources cv::Mat images[kCcameraNums]; eyecams[0] = std::make_unique("Pupil Cam1 ID2"); std::string window_names[kCcameraNums] = { "Cam0" }; for (size_t cam = 0; cam < kCcameraNums; cam++){ // Check if the cameras are opened if (eyecams[cam]->isOpened() == false){ std::cout << "Could not open the camera" << std::endl; return; } // Capture single frames to get image sizes; for (size_t cam = 0; cam < kCcameraNums; cam++){ eyecams[cam]->fetchFrame(images[cam]); if (images[cam].empty()){ std::cout << "Could not capture an image" << std::endl; return; } } } // Create an image buffer size of the number of cameras and their frame length cv::Mat buffer_images[kCcameraNums][kMaxCaptureFrame]; for (size_t i = 0; i < kMaxCaptureFrame; i++){ for (size_t cam = 0; cam < kCcameraNums; cam++){ buffer_images[cam][i] = cv::Mat::zeros(images[0].size(), images[0].type()); } } // Capture and store images size_t frame_count = 0; timer timer0; timer0.pause(); for( size_t i = 0; i < kMaxCaptureFrame; i++){ // while (frame_countfetchFrame(images[cam]); if (images[cam].empty()){ std::cout << "Could not capture an image" << std::endl; return; } } // Copy the cpatured images to the buffer for (size_t cam = 0; cam < kCcameraNums; cam++){ cv::Mat &img = images[cam]; cv::imshow(window_names[cam], img); img.copyTo(buffer_images[cam][i]); } cv::waitKey(5); // Compute FPS frame_count++; const size_t kSkipFrameCount = 50; if (frame_count == kSkipFrameCount)timer0.resume(); /// Wait measuring time until the process gets stabilized const double kFPS = (frame_count - kSkipFrameCount) / timer0.elapsed(); std::cout << "FPS=" << kFPS << ", 2D pupil params " << std::endl; // Print current frame data } // Save buffered images to files std::ostringstream ost_frame_id; const std::string kDir = "./tmp/"; const std::streamsize kStreamSize = 3; const char kPaddingChar = '0'; const std::string kImageFormat = "png"; for (size_t cam = 0; cam < kCcameraNums; cam++){ std::ostringstream ost_video_name; ost_video_name << kDir<<"cam" << cam << ".avi"; cv::VideoWriter outputVideo(ost_video_name.str(), -1, 30, buffer_images[cam][0].size()); for (size_t i = 0; i < kMaxCaptureFrame; i++){ ost_frame_id.str(""); ost_frame_id.clear(); ost_frame_id << "cam"<> frame; } else { frame = mono_img_.clone(); } if (is_flipped_) cv::flip(frame, frame, -1);//flip both } EyeCameraDS::EyeCameraDS(std::string cam_name) : DSfg(cam_name) { DSfg.start(); } EyeCameraDS::~EyeCameraDS(){ DSfg.stop(); } bool EyeCameraDS::isOpened(){ return true; } void EyeCameraDS::fetchFrame(cv::Mat &frame){ DSfg.getFrame(frame); } } // namespace