void run() { if (!setup_capture_source()) { std::cout << "Could not initialize capture source" << std::endl; return; } cv::Size output_size = get_output_size(); size_t full_image_dimensions = output_size.width * output_size.height * 3; m_framework = create_message_framework(m_direction, full_image_dimensions); if (m_framework == NULL) { std::cout << "Could not initialize message framework" << std::endl; return; } std::cout << "Set up camera. Starting image acquisition" << std::endl; long last_acq_time = 0; while (running) { std::experimental::optional<std::pair<cv::Mat, long>> next_image_op = acquire_next_image(); if (!next_image_op) { std::cout << "Error acquiring image! Trying again." << std::endl; continue; } cv::Mat next_image = next_image_op.value().first; long acq_time = next_image_op.value().second; write_frame(m_framework, next_image.data, acq_time, output_size.width, output_size.height, 3); long curr_time = get_time(); long time_since_last_acq = curr_time - last_acq_time; long min_acq_time = 1000 / m_max_fps; auto sleep_time = std::chrono::milliseconds(min_acq_time - time_since_last_acq); if (sleep_time > std::chrono::milliseconds(0)) { std::this_thread::sleep_for(sleep_time); } last_acq_time = acq_time; } destroy_capture_source(); std::cout << "Cleaned up capture source" << std::endl; cleanup_message_framework(m_framework); std::cout << "Cleaned up message framework" << std::endl; }
message_framework_p create_message_framework_from_cstring(const char *direction, size_t max_image_size) { return create_message_framework(std::string(direction), max_image_size); }