|
| 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 | +} |
0 commit comments