rgbd
serialization_gtest.cpp
Go to the documentation of this file.
1 #include "test_utils.h"
2 
3 #include <gtest/gtest.h>
4 
5 #include <opencv2/core.hpp>
6 #include <opencv2/imgcodecs.hpp>
7 
8 #include <rgbd/image.h>
9 #include <rgbd/serialization.h>
10 
13 
14 #include <sstream>
15 
16 
17 class Serialization : public testing::Test
18 {
19 protected:
20  void SetUp() override
21  {
23  }
24 
26 };
27 
29 {
31  tue::serialization::OutputArchive output_achive(ss);
32 
33  EXPECT_TRUE(rgbd::serialize(image1, output_achive, rgbd::RGB_STORAGE_LOSSLESS, rgbd::DEPTH_STORAGE_LOSSLESS));
34  tue::serialization::InputArchive input_achive(ss);
35  rgbd::Image image2;
36  EXPECT_TRUE(rgbd::deserialize(input_achive, image2));
37 
38  EXPECT_EQ(image1, image2);
39 }
40 
42 {
44  tue::serialization::OutputArchive output_achive(ss);
45 
46  EXPECT_TRUE(rgbd::serialize(image1, output_achive, rgbd::RGB_STORAGE_JPG, rgbd::DEPTH_STORAGE_LOSSLESS));
47  tue::serialization::InputArchive input_achive(ss);
48  rgbd::Image image2;
49  EXPECT_TRUE(rgbd::deserialize(input_achive, image2));
50 
51  std::vector<int> rgb_params;
52  rgb_params.resize(2, 0);
53  rgb_params[0] = cv::IMWRITE_JPEG_QUALITY;
54  rgb_params[1] = 95; // default is 95
55 
57 
58  // Compress image
59  cv::imencode(".jpg", image1.getRGBImage(), rgb_data, rgb_params);
60  image1.setRGBImage(cv::imdecode(rgb_data, cv::IMREAD_UNCHANGED));
61 
62  EXPECT_EQ(image1, image2);
63 }
64 
65 // Run all the tests that were declared with TEST()
66 int main(int argc, char **argv)
67 {
68  testing::InitGoogleTest(&argc, argv);
69  return RUN_ALL_TESTS();
70 }
sstream
std::vector::resize
T resize(T... args)
input_archive.h
test_utils.h
std::vector
rgbd::deserialize
bool deserialize(tue::serialization::InputArchive &a, Image &image)
Definition: serialization.cpp:174
std::stringstream
tue::serialization::OutputArchive
Serialization
Definition: serialization_gtest.cpp:17
Serialization::SetUp
void SetUp() override
Definition: serialization_gtest.cpp:20
rgbd::serialize
bool serialize(const Image &image, tue::serialization::OutputArchive &a, RGBStorageType rgb_type=RGB_STORAGE_JPG, DepthStorageType depth_type=DEPTH_STORAGE_PNG)
Definition: serialization.cpp:23
rgbd::Image
Definition: image.h:43
TEST_F
TEST_F(Serialization, LossLess)
Definition: serialization_gtest.cpp:28
rgbd::RGB_STORAGE_JPG
@ RGB_STORAGE_JPG
Definition: image.h:33
image.h
tue::serialization::InputArchive
rgbd::RGB_STORAGE_LOSSLESS
@ RGB_STORAGE_LOSSLESS
Definition: image.h:32
serialization.h
rgbd::DEPTH_STORAGE_LOSSLESS
@ DEPTH_STORAGE_LOSSLESS
Definition: image.h:39
output_archive.h
Serialization::image1
rgbd::Image image1
Definition: serialization_gtest.cpp:25
rgbd::generateRandomImage
rgbd::Image generateRandomImage()
Definition: test_utils.h:36
main
int main(int argc, char **argv)
Definition: serialization_gtest.cpp:66