JPGRecordingStrategy.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * ArmarX is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * ArmarX is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * @package visionx::imrec
17  * @author Christian R. G. Dreher <christian.dreher@student.kit.edu>
18  * @date 2018
19  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20  * GNU General Public License
21  */
22 
23 
25 
26 
27 // STD/STL
28 #include <vector>
29 
30 // OpenCV 2
31 #include <opencv2/opencv.hpp>
32 
33 // ArmarX
35 
37 {
38  // pass
39 }
40 
42  const std::filesystem::path& filePath,
43  const std::string& name,
44  unsigned int jpg_quality) :
45  visionx::imrec::AbstractSequencedRecordingStrategy(filePath / name, ".jpg"),
46  m_jpg_quality{jpg_quality}
47 {
48  // jpg_quality is unsigned, therefore this check is nonsensical!
49  // ARMARX_CHECK_GREATER_EQUAL(jpg_quality, 0) << "Quality cannot be lower than 0.";
50  ARMARX_CHECK_LESS_EQUAL(jpg_quality, 100) << "Quality cannot be greater than 100.";
51 }
52 
54 {
55  // pass
56 }
57 
58 void
60 {
62  writeMetadataLine("jpg_quality", "unsigned int", std::to_string(m_jpg_quality));
63 }
64 
65 void
67  const std::chrono::microseconds timestamp)
68 {
69  const auto& [sequence_number, frame_name] = writeMetadataFrame(frame, timestamp);
70  const std::filesystem::path path = deriveFramePath(sequence_number, frame_name);
71  std::vector<int> params{cv::IMWRITE_JPEG_QUALITY, static_cast<int>(m_jpg_quality)};
72  cv::imwrite(path.string(), frame, params);
73 }
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::imrec::strats::JPGRecordingStrategy::recordFrame
void recordFrame(const cv::Mat &frame, std::chrono::microseconds timestamp) override
Adds the given frame to the recording.
Definition: JPGRecordingStrategy.cpp:66
visionx::imrec::strats::JPGRecordingStrategy::startRecording
void startRecording() override
Starts the recording manually if constructed empty.
Definition: JPGRecordingStrategy.cpp:59
visionx::imrec::AbstractSequencedRecordingStrategy
An object of this class behaves likee a normal recording, but is in fact a sequence of images.
Definition: AbstractSequencedRecordingStrategy.h:40
JPGRecordingStrategy.h
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:41
ARMARX_CHECK_LESS_EQUAL
#define ARMARX_CHECK_LESS_EQUAL(lhs, rhs)
This macro evaluates whether lhs is less or equal (<=) rhs and if it turns out to be false it will th...
Definition: ExpressionException.h:109
visionx::imrec::strats::JPGRecordingStrategy::JPGRecordingStrategy
JPGRecordingStrategy()
Definition: JPGRecordingStrategy.cpp:36
ExpressionException.h
visionx::imrec::strats::JPGRecordingStrategy::~JPGRecordingStrategy
~JPGRecordingStrategy() override
Definition: JPGRecordingStrategy.cpp:53
visionx::imrec::AbstractSequencedRecordingStrategy::startRecording
void startRecording() override
Starts the recording manually if constructed empty.
Definition: AbstractSequencedRecordingStrategy.cpp:65