Skip to content

Commit 5272aca

Browse files
Full library setup. Unit tests. Doxygen docs.
1 parent cecf1ce commit 5272aca

30 files changed

+5365
-80
lines changed

Doxyfile

Lines changed: 2818 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2024 TeiaCare
190+
Copyright 2025 TeiaCare
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this project except in compliance with the License.

cmake/examples.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function(add_example EXAMPLE_NAME)
2-
add_executable(${EXAMPLE_NAME} src/${EXAMPLE_NAME}.cpp src/utils/video_data_path.cpp)
2+
add_executable(${EXAMPLE_NAME} examples/${EXAMPLE_NAME}.cpp)
33
target_compile_features(${EXAMPLE_NAME} PUBLIC cxx_std_20)
4-
target_link_libraries(${EXAMPLE_NAME} PRIVATE teiacare::video_io)
4+
target_link_libraries(${EXAMPLE_NAME} PRIVATE teiacare::image)
55
install(TARGETS ${EXAMPLE_NAME} DESTINATION examples)
66
endfunction()

cmake/options.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
55
set(WINDOWS_EXPORT_ALL_SYMBOLS ON)
66
set(CONAN_CMAKE_SILENT_OUTPUT ON)
77

8-
option(TC_ENABLE_UNIT_TESTS "Enable Unit Tests" False)
8+
option(TC_ENABLE_UNIT_TESTS "Enable Unit Tests" True)
99
cmake_print_variables(TC_ENABLE_UNIT_TESTS)
1010

1111
option(TC_ENABLE_UNIT_TESTS_COVERAGE "Enable Unit Tests Coverage" False)

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright 2024 TeiaCare
2+
# Copyright 2025 TeiaCare
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.

image/CMakeLists.txt

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,19 @@ configure_file(
1010
)
1111

1212
set(TARGET_HEADERS
13-
include/teiacare/image/img.hpp
13+
include/teiacare/image/image_color.hpp
14+
include/teiacare/image/image_draw.hpp
15+
include/teiacare/image/image_io.hpp
16+
include/teiacare/image/image_processing.hpp
17+
include/teiacare/image/image_resize.hpp
1418
include/teiacare/image/version.hpp
1519
)
1620

1721
set(TARGET_SOURCES
18-
src/img.cpp
22+
src/image_color.cpp
23+
src/image_io.cpp
24+
src/image_draw.cpp
25+
src/image_resize.cpp
1926
src/version.cpp
2027
)
2128

@@ -61,16 +68,19 @@ if(TC_ENABLE_UNIT_TESTS)
6168

6269
set(UNIT_TESTS_SRC
6370
tests/main.cpp
71+
tests/test_image_color.cpp
72+
tests/test_image_draw.cpp
73+
tests/test_image_io.cpp
74+
tests/test_image_processing.cpp
75+
tests/test_image_resize.cpp
6476
)
6577

6678
add_executable(${TEST_TARGET_NAME})
6779
target_sources(${TEST_TARGET_NAME} PRIVATE ${UNIT_TESTS_SRC})
68-
target_include_directories(${TEST_TARGET_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/proto)
6980
target_compile_features(${TEST_TARGET_NAME} PUBLIC cxx_std_20)
7081
target_link_libraries(${TEST_TARGET_NAME}
7182
PRIVATE
7283
GTest::gtest
73-
GTest::gmock
7484
teiacare::image
7585
)
7686

@@ -91,8 +101,9 @@ endif()
91101
#################################################################
92102
# Examples
93103
if(TC_ENABLE_EXAMPLES)
94-
add_executable(example_image examples/example.cpp)
95-
target_compile_features(example_image PUBLIC cxx_std_20)
96-
target_link_libraries(example_image PRIVATE teiacare::image)
97-
install(TARGETS example_image DESTINATION examples)
104+
include(examples)
105+
add_example(example_image_io)
106+
add_example(example_image_draw)
107+
add_example(example_image_resize)
108+
add_example(example_image_preprocessing)
98109
endif()
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2025 TeiaCare
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @example example_image_draw.cpp
17+
* @brief Drawing primitives example demonstrating tc::img::draw_rectangle, tc::img::draw_polygon, and tc::img::color usage
18+
*/
19+
20+
#include <teiacare/image/image_draw.hpp>
21+
#include <teiacare/image/image_io.hpp>
22+
23+
#include <filesystem>
24+
#include <iostream>
25+
#include <vector>
26+
27+
int main(int, char**)
28+
{
29+
// Load image from jpeg file
30+
const std::filesystem::path input_image_path = "img.jpeg";
31+
auto [img_data, width, height, channels] = tc::img::image_load(input_image_path);
32+
33+
{
34+
std::array<int, 4> box = {50, 50, 200, 100};
35+
tc::img::color color = tc::img::color::red();
36+
int thickness = 1;
37+
draw_rectangle(img_data, width, height, box[0], box[1], box[2], box[3], color, thickness);
38+
}
39+
40+
{
41+
std::array<int, 4> box = {300, 200, 150, 250};
42+
tc::img::color color(255, 165, 0); // Orange color
43+
int thickness = 3;
44+
draw_rectangle(img_data, width, height, box[0], box[1], box[2], box[3], color, thickness);
45+
}
46+
47+
{
48+
std::vector<std::pair<int, int>> polygon = {{100, 500}, {200, 600}, {50, 600}};
49+
draw_polygon(img_data, width, height, polygon, tc::img::color(0, 0, 255), 3);
50+
}
51+
52+
{
53+
std::vector<std::pair<int, int>> polygon = {{150, 350}, {250, 320}, {320, 380}, {280, 450}, {200, 480}, {120, 460}, {80, 400}};
54+
draw_polygon(img_data, width, height, polygon, tc::img::color(0, 255, 127), 2);
55+
}
56+
57+
// Save image to png file
58+
const std::filesystem::path output_image_path = "img_draw.png";
59+
tc::img::image_save(output_image_path, img_data, width, height, channels);
60+
61+
return 0;
62+
}
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 TeiaCare
1+
// Copyright 2025 TeiaCare
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -12,35 +12,38 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <teiacare/image/img.hpp>
15+
/**
16+
* @example example_image_io.cpp
17+
* @brief Image input/output example demonstrating tc::img::image_load, tc::img::image_save, tc::img::image_load_as_binary, and tc::img::image_load_from_memory
18+
*/
19+
20+
#include <teiacare/image/image_io.hpp>
1621

1722
#include <filesystem>
18-
#include <iostream>
19-
#include <vector>
2023

21-
int main(int argc, char** argv)
24+
int main(int, char**)
2225
{
2326
{
2427
// Load image from jpeg file
2528
const std::filesystem::path input_image_path = "img.jpeg";
26-
auto [img_data, width, height, channels] = tc::img::load_image(input_image_path);
29+
auto [img_data, width, height, channels] = tc::img::image_load(input_image_path);
2730

2831
// Save image to png file
2932
const std::filesystem::path output_image_path = "img.png";
30-
tc::img::save_image(output_image_path, img_data, width, height, channels);
33+
tc::img::image_save(output_image_path, img_data, width, height, channels);
3134
}
3235

3336
{
3437
// Load image from binary data
3538
const std::filesystem::path input_image_path = "img.jpeg";
36-
auto bin_img = tc::img::load_image_as_binary(input_image_path);
39+
auto bin_img = tc::img::image_load_as_binary(input_image_path);
3740

3841
// Create image data from binary image data
39-
auto [img_data, width, height, channels] = tc::img::load_image_from_memory(bin_img.data(), bin_img.size());
42+
auto [img_data, width, height, channels] = tc::img::image_load_from_memory(bin_img.data(), bin_img.size());
4043

4144
// Save image to png file
4245
const std::filesystem::path output_image_path = "out.png";
43-
tc::img::save_image(output_image_path, img_data, width, height, channels);
46+
tc::img::image_save(output_image_path, img_data, width, height, channels);
4447
}
4548

4649
return 0;
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2025 TeiaCare
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @example example_image_preprocessing.cpp
17+
* @brief Image preprocessing pipeline example demonstrating tc::img::image_resize_aspect_ratio and tc::img::create_blob for ML preprocessing
18+
*/
19+
20+
#include <teiacare/image/image_io.hpp>
21+
#include <teiacare/image/image_processing.hpp>
22+
#include <teiacare/image/image_resize.hpp>
23+
24+
#include <cassert>
25+
#include <filesystem>
26+
#include <iostream>
27+
#include <vector>
28+
29+
int main(int argc, char** argv)
30+
{
31+
// Load image from jpeg file
32+
const std::filesystem::path input_image_path = "img.jpeg";
33+
auto [img_data, width, height, channels] = tc::img::image_load(input_image_path);
34+
35+
// Preprocess image with aspect ratio resizing and blob creation
36+
const int target_width = 640;
37+
const int target_height = 640;
38+
const float scale_factor = 1.0f / 255.0f;
39+
const std::vector<float> mean = {0.0f, 0.0f, 0.0f};
40+
const bool swapRB_channels = false;
41+
42+
const std::vector<std::uint8_t> resized_image = tc::img::image_resize_aspect_ratio(img_data, width, height, channels, target_width, target_height);
43+
const std::vector<float> blob = tc::img::create_blob(resized_image, target_width, target_height, channels, scale_factor, mean, swapRB_channels);
44+
45+
std::cout << "Blob size: " << blob.size() << std::endl;
46+
std::cout << "Img size: " << target_width * target_height * channels << std::endl;
47+
assert(blob.size() == target_width * target_height * channels);
48+
49+
return 0;
50+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2025 TeiaCare
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @example example_image_resize.cpp
17+
* @brief Image resizing example demonstrating tc::img::image_resize_aspect_ratio for preserving aspect ratio during resize operations
18+
*/
19+
20+
#include <teiacare/image/image_io.hpp>
21+
#include <teiacare/image/image_resize.hpp>
22+
23+
#include <filesystem>
24+
#include <iostream>
25+
#include <vector>
26+
27+
int main(int argc, char** argv)
28+
{
29+
// Load image from jpeg file
30+
const std::filesystem::path input_image_path = "img.jpeg";
31+
auto [img_data, width, height, channels] = tc::img::image_load(input_image_path);
32+
33+
// Resize image to 300x300 while preserving aspect ratio
34+
const int target_width = 300;
35+
const int target_height = 300;
36+
auto resized_image = tc::img::image_resize_aspect_ratio(img_data, width, height, channels, target_width, target_height);
37+
38+
// Save image to png file
39+
const std::filesystem::path output_image_path = "img_resized.png";
40+
tc::img::image_save(output_image_path, resized_image, target_width, target_height, channels);
41+
42+
return 0;
43+
}

0 commit comments

Comments
 (0)