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
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
57
58void
64
65void
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}
std::string timestamp()
virtual std::tuple< unsigned int, std::string > writeMetadataFrame(const CByteImage &frame, std::chrono::microseconds timestamp)
virtual void writeMetadataLine(const std::string &var_name, std::string_view var_type, std::string_view var_value)
void startRecording() override
Starts the recording manually if constructed empty.
AbstractSequencedRecordingStrategy()
Default constructor to manually start the recording.
std::filesystem::path deriveFramePath(const unsigned int sequence_number, const std::string &frame_name)
Returns the next sequenced full path and increments the sequence number.
void startRecording() override
Starts the recording manually if constructed empty.
void recordFrame(const cv::Mat &frame, std::chrono::microseconds timestamp) override
Adds the given frame to the recording.
#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...
ArmarX headers.