Visual Servoing Platform
version 3.6.0
Loading...
Searching...
No Matches
vpImageStorageWorker.h
1
/*
2
* ViSP, open source Visual Servoing Platform software.
3
* Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4
*
5
* This software is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
* See the file LICENSE.txt at the root directory of this source
10
* distribution for additional information about the GNU GPL.
11
*
12
* For using ViSP with software that can not be combined with the GNU
13
* GPL, please contact Inria about acquiring a ViSP Professional
14
* Edition License.
15
*
16
* See https://visp.inria.fr for more information.
17
*
18
* This software was developed at:
19
* Inria Rennes - Bretagne Atlantique
20
* Campus Universitaire de Beaulieu
21
* 35042 Rennes Cedex
22
* France
23
*
24
* If you have questions regarding the use of this file, please contact
25
* Inria at visp@inria.fr
26
*
27
* This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28
* WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29
*
30
* Description:
31
* Image storage helper.
32
*/
33
34
#ifndef vpImageStorageWorker_h
35
#define vpImageStorageWorker_h
36
37
#include <visp3/core/vpConfig.h>
38
39
#if (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
40
41
#include <visp3/io/vpImageIo.h>
42
#include <visp3/io/vpImageQueue.h>
43
52
template
<
class
Type>
class
vpImageStorageWorker
53
{
54
public
:
59
vpImageStorageWorker
(
vpImageQueue<Type>
&queue)
60
: m_queue(queue), m_dataname(
""
), m_cpt(1), m_ofs_data(), m_data_file_created(false)
61
{
62
m_seqname = queue.
getSeqName
();
63
m_record_mode = queue.
getRecordingMode
();
64
}
65
69
void
run
()
70
{
71
try
{
72
vpImage<Type>
I;
73
std::string data;
74
char
filename[FILENAME_MAX];
75
76
for
(;;) {
77
m_queue.pop(I, data);
78
79
// Save image
80
snprintf(filename, FILENAME_MAX, m_seqname.c_str(), m_cpt);
81
82
if
(m_record_mode > 0) {
// Single image
83
std::cout <<
"Save image: "
<< filename << std::endl;
84
}
else
if
(m_cpt == 1) {
85
std::cout <<
"Started sequence saving: "
<< m_seqname << std::endl;
86
}
87
vpImageIo::write
(I, filename);
88
89
if
(!data.empty()) {
90
if
(!m_data_file_created) {
91
std::string parent =
vpIoTools::getParent
(m_seqname);
92
if
(!parent.empty()) {
93
m_dataname =
vpIoTools::getParent
(m_seqname) +
"/"
;
94
}
95
m_dataname +=
vpIoTools::getNameWE
(m_seqname);
96
m_dataname +=
".txt"
;
97
98
std::cout <<
"Create data file: "
<< m_dataname << std::endl;
99
m_ofs_data.open(m_dataname);
100
101
m_data_file_created =
true
;
102
}
103
m_ofs_data <<
vpIoTools::getName
(filename) <<
" "
<< data << std::endl;
104
}
105
106
m_cpt++;
107
}
108
}
catch
(
const
vpImageQueue<vpRGBa>::cancelled
&) {
109
std::cout <<
"Receive cancel during color image saving."
<< std::endl;
110
if
(m_data_file_created) {
111
std::cout <<
"Close data file: "
<< m_dataname << std::endl;
112
m_ofs_data.close();
113
}
114
}
catch
(
const
vpImageQueue<unsigned char>::cancelled
&) {
115
std::cout <<
"Receive cancel during gray image saving."
<< std::endl;
116
if
(m_data_file_created) {
117
std::cout <<
"Close data file: "
<< m_dataname << std::endl;
118
m_ofs_data.close();
119
}
120
}
121
}
122
123
private
:
124
vpImageQueue<Type>
&m_queue;
125
std::string m_seqname;
126
std::string m_dataname;
127
int
m_record_mode;
128
unsigned
int
m_cpt;
129
std::ofstream m_ofs_data;
130
bool
m_data_file_created;
131
};
132
133
#endif
134
#endif
vpImageIo::write
static void write(const vpImage< unsigned char > &I, const std::string &filename, int backend=IO_DEFAULT_BACKEND)
Definition
vpImageIo.cpp:287
vpImageQueue
Definition
vpImageQueue.h:62
vpImageQueue::getRecordingMode
int getRecordingMode() const
Definition
vpImageQueue.h:102
vpImageQueue::getSeqName
std::string getSeqName() const
Definition
vpImageQueue.h:112
vpImageStorageWorker
Definition
vpImageStorageWorker.h:53
vpImageStorageWorker::run
void run()
Definition
vpImageStorageWorker.h:69
vpImageStorageWorker::vpImageStorageWorker
vpImageStorageWorker(vpImageQueue< Type > &queue)
Definition
vpImageStorageWorker.h:59
vpImage
Definition of the vpImage class member functions.
Definition
vpImage.h:135
vpIoTools::getNameWE
static std::string getNameWE(const std::string &pathname)
Definition
vpIoTools.cpp:1586
vpIoTools::getParent
static std::string getParent(const std::string &pathname)
Definition
vpIoTools.cpp:1669
vpIoTools::getName
static std::string getName(const std::string &pathname)
Definition
vpIoTools.cpp:1564
vpImageQueue::cancelled
Definition
vpImageQueue.h:64
modules
io
include
visp3
io
vpImageStorageWorker.h
Generated by
1.12.0