34 #ifndef vpImageQueue_h
35 #define vpImageQueue_h
37 #include <visp3/core/vpConfig.h>
39 #if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11) && defined(VISP_HAVE_THREADS)
41 #include <condition_variable>
47 #include <visp3/core/vpDisplay.h>
48 #include <visp3/core/vpIoTools.h>
52 #ifndef DOXYGEN_SHOULD_SKIP_THIS
64 template <
class Type>
class vpImageQueue
77 vpImageQueue(
const std::string &seqname,
int record_mode)
78 : m_cancelled(false), m_cond(), m_queue_image(), m_queue_data(), m_maxQueueSize(1024 * 8), m_mutex(),
79 m_seqname(seqname), m_recording_mode(record_mode), m_start_recording(false), m_directory_to_create(false),
80 m_recording_trigger(false)
83 if (!m_directory.empty()) {
85 m_directory_to_create =
true;
89 std::string(
"Record mode: ") + (m_recording_mode ? std::string(
"single") : std::string(
"continuous"));
97 std::lock_guard<std::mutex> lock(m_mutex);
98 std::cout <<
"Wait to finish saving images..." << std::endl;
106 int getRecordingMode()
const {
return m_recording_mode; }
111 bool getRecordingTrigger()
const {
return m_recording_trigger; }
116 std::string getSeqName()
const {
return m_seqname; }
127 std::unique_lock<std::mutex> lock(m_mutex);
129 while (m_queue_image.empty()) {
131 throw vpCancelled_t();
137 throw vpCancelled_t();
141 I = m_queue_image.front();
145 if (!m_queue_data.empty()) {
146 data = m_queue_data.front();
159 std::lock_guard<std::mutex> lock(m_mutex);
161 m_queue_image.push(I);
163 if (data !=
nullptr) {
164 m_queue_data.push(*data);
168 while (m_queue_image.size() > m_maxQueueSize) {
172 if (data !=
nullptr) {
173 while (m_queue_data.size() > m_maxQueueSize) {
190 bool record(
const vpImage<Type> &I, std::string *data =
nullptr,
bool trigger_recording =
false,
191 bool disable_left_click =
false)
194 if (!m_seqname.empty()) {
195 if (!disable_left_click) {
196 if (!m_recording_mode) {
197 if (m_start_recording) {
221 if (!m_seqname.empty()) {
227 if (!m_seqname.empty()) {
229 m_start_recording = !m_start_recording;
240 else if (!m_seqname.empty()) {
241 m_start_recording =
true;
244 if (trigger_recording) {
245 m_start_recording =
true;
248 m_recording_trigger = m_start_recording;
250 if (m_start_recording) {
252 if (m_directory_to_create) {
253 std::cout <<
"Create directory \"" << m_directory <<
"\"" << std::endl;
255 m_directory_to_create =
false;
260 if (m_recording_mode == 1) {
261 m_start_recording =
false;
271 void setMaxQueueSize(
const size_t max_queue_size) { m_maxQueueSize = max_queue_size; }
275 std::condition_variable m_cond;
276 std::queue<vpImage<Type> > m_queue_image;
277 std::queue<std::string> m_queue_data;
278 size_t m_maxQueueSize;
280 std::string m_seqname;
281 std::string m_directory;
282 int m_recording_mode;
283 bool m_start_recording;
284 std::string m_text_record_mode;
285 bool m_directory_to_create;
286 bool m_recording_trigger;
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
unsigned int getDownScalingFactor()
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Definition of the vpImage class member functions.