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 
36 
38 {
39  // pass
40 }
41 
42 
43 visionx::imrec::strats::JPGRecordingStrategy::JPGRecordingStrategy(const std::filesystem::path& filePath, const std::string& name, unsigned int jpg_quality) :
44  visionx::imrec::AbstractSequencedRecordingStrategy(filePath / name, ".jpg"),
45  m_jpg_quality{jpg_quality}
46 {
47  // jpg_quality is unsigned, therefore this check is nonsensical!
48  // ARMARX_CHECK_GREATER_EQUAL(jpg_quality, 0) << "Quality cannot be lower than 0.";
49  ARMARX_CHECK_LESS_EQUAL(jpg_quality, 100) << "Quality cannot be greater than 100.";
50 }
51 
52 
54 {
55  // pass
56 }
57 
58 
59 void
61 {
63  writeMetadataLine("jpg_quality", "unsigned int", std::to_string(m_jpg_quality));
64 }
65 
66 
67 void
68 visionx::imrec::strats::JPGRecordingStrategy::recordFrame(const cv::Mat& frame, const std::chrono::microseconds timestamp)
69 {
70  const auto& [sequence_number, frame_name] = writeMetadataFrame(frame, timestamp);
71  const std::filesystem::path path = deriveFramePath(sequence_number, frame_name);
72  std::vector<int> params {cv::IMWRITE_JPEG_QUALITY, static_cast<int>(m_jpg_quality)};
73  cv::imwrite(path.string(), frame, params);
74 }
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:68
visionx::imrec::strats::JPGRecordingStrategy::startRecording
void startRecording() override
Starts the recording manually if constructed empty.
Definition: JPGRecordingStrategy.cpp:60
visionx::imrec::AbstractSequencedRecordingStrategy
An object of this class behaves likee a normal recording, but is in fact a sequence of images.
Definition: AbstractSequencedRecordingStrategy.h:41
JPGRecordingStrategy.h
armarx::to_string
const std::string & to_string(const std::string &s)
Definition: StringHelpers.h:40
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:37
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:67