Skip to content

Commit 857348b

Browse files
committed
vision: update CMakeLists, detector, image, OCR, tracker modules and corresponding tests
1 parent 342d755 commit 857348b

13 files changed

Lines changed: 179 additions & 123 deletions

File tree

CMakeLists.txt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
11
cmake_minimum_required(VERSION 3.20)
22

3-
project(vix-ai-vision
3+
project(vision
44
VERSION 0.1.0
55
DESCRIPTION "Vix.AI Vision: image primitives, detector, tracker, OCR (header-only v0)"
66
LANGUAGES CXX)
77

8-
option(VIX_AI_VISION_BUILD_TESTS "Build vix-ai-vision tests" ON)
9-
option(VIX_AI_VISION_INSTALL "Install vix-ai-vision targets" ON)
8+
option(VIX_AI_VISION_BUILD_TESTS "Build vision tests" ON)
9+
option(VIX_AI_VISION_INSTALL "Install vision targets" ON)
1010
option(VIX_AI_VISION_WARNINGS "Enable extra warnings" ON)
1111

12+
# ---- Library target ---------------------------------------------------------
1213
add_library(vix_ai_vision INTERFACE)
1314
add_library(Vix::AI::vision ALIAS vix_ai_vision)
1415

1516
target_include_directories(vix_ai_vision INTERFACE
1617
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
17-
$<INSTALL_INTERFACE:include>)
18+
$<INSTALL_INTERFACE:include>
19+
)
1820

1921
target_compile_features(vix_ai_vision INTERFACE cxx_std_20)
2022

21-
if (DEFINED VIX_AI_VERSION)
23+
if(DEFINED VIX_AI_VERSION)
2224
set(PROJECT_VERSION ${VIX_AI_VERSION})
2325
endif()
26+
2427
target_compile_definitions(vix_ai_vision INTERFACE VIX_AI_VISION_VERSION="${PROJECT_VERSION}")
2528

26-
if (VIX_AI_VISION_WARNINGS)
27-
if (MSVC)
29+
if(VIX_AI_VISION_WARNINGS)
30+
if(MSVC)
2831
target_compile_options(vix_ai_vision INTERFACE /W4 /permissive-)
2932
else()
3033
target_compile_options(vix_ai_vision INTERFACE -Wall -Wextra -Wpedantic)
3134
endif()
3235
endif()
3336

34-
# Tests
35-
if (VIX_AI_VISION_BUILD_TESTS)
37+
# ---- Tests ------------------------------------------------------------------
38+
if(VIX_AI_VISION_BUILD_TESTS)
3639
enable_testing()
37-
add_subdirectory(tests)
40+
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests")
41+
add_subdirectory(tests)
42+
endif()
3843
endif()
3944

40-
# Install / package
41-
if (VIX_AI_VISION_INSTALL)
45+
# ---- Install / Package ------------------------------------------------------
46+
if(VIX_AI_VISION_INSTALL)
4247
include(GNUInstallDirs)
4348
include(CMakePackageConfigHelpers)
4449

@@ -50,7 +55,7 @@ if (VIX_AI_VISION_INSTALL)
5055
install(EXPORT vix_ai_visionTargets
5156
FILE vix_ai_visionTargets.cmake
5257
NAMESPACE Vix::AI::
53-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai_vision)
58+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai/vision)
5459

5560
write_basic_package_version_file(
5661
${CMAKE_CURRENT_BINARY_DIR}/vix_ai_visionConfigVersion.cmake
@@ -63,5 +68,5 @@ if (VIX_AI_VISION_INSTALL)
6368
install(FILES
6469
${CMAKE_CURRENT_BINARY_DIR}/vix_ai_visionConfig.cmake
6570
${CMAKE_CURRENT_BINARY_DIR}/vix_ai_visionConfigVersion.cmake
66-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai_vision)
71+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai/vision)
6772
endif()

include/vix/ai/vision/Detector.hpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,33 @@
1-
#pragma once
1+
/**
2+
* @file Detector.hpp
3+
* @author Gaspard Kirira
4+
*
5+
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* https://github.com/vixcpp/vix
7+
* Use of this source code is governed by a MIT license that can be found in the License file.
8+
*
9+
* Vix.cpp
10+
*/
11+
#ifndef VIX_AI_VISION_DETECTOR_HPP
12+
#define VIX_AI_VISION_DETECTOR_HPP
13+
214
#include <vector>
315
#include <array>
416
#include "Image.hpp"
517

618
namespace vix::ai::vision
719
{
20+
using BBox = std::array<int, 4>;
821

9-
// Bounding box: {x, y, w, h}
10-
using BBox = std::array<int, 4>;
11-
12-
struct Detector
22+
struct Detector
23+
{
24+
std::vector<BBox> detect(const Image &img) const
1325
{
14-
// v0 stub: returns empty vec, but checks image validity
15-
std::vector<BBox> detect(const Image &img) const
16-
{
17-
img.assert_not_empty("Detector::detect");
18-
return {};
19-
}
20-
};
26+
img.assert_not_empty("Detector::detect");
27+
return {};
28+
}
29+
};
2130

2231
} // namespace vix::ai::vision
32+
33+
#endif

include/vix/ai/vision/Image.hpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
1-
#pragma once
1+
/**
2+
* @file Image.hpp
3+
* @author Gaspard Kirira
4+
*
5+
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* https://github.com/vixcpp/vix
7+
* Use of this source code is governed by a MIT license that can be found in the License file.
8+
*
9+
* Vix.cpp
10+
*/
11+
#ifndef VIX_AI_VISION_IMAGE_HPP
12+
#define VIX_AI_VISION_IMAGE_HPP
13+
214
#include <cstddef>
315
#include <stdexcept>
416
#include <string>
517

618
namespace vix::ai::vision
719
{
820

9-
struct Image
10-
{
11-
std::size_t w{}; // width in pixels
12-
std::size_t h{}; // height in pixels
21+
struct Image
22+
{
23+
// width in pixels
24+
std::size_t w{};
1325

14-
constexpr Image() = default;
15-
constexpr Image(std::size_t width, std::size_t height) : w(width), h(height) {}
26+
// height in pixels
27+
std::size_t h{};
1628

17-
constexpr bool empty() const noexcept { return w == 0 || h == 0; }
18-
constexpr std::size_t width() const noexcept { return w; }
19-
constexpr std::size_t height() const noexcept { return h; }
20-
constexpr std::size_t area() const noexcept { return w * h; }
29+
constexpr Image() = default;
30+
constexpr Image(std::size_t width, std::size_t height) : w(width), h(height) {}
31+
constexpr bool empty() const noexcept { return w == 0 || h == 0; }
32+
constexpr std::size_t width() const noexcept { return w; }
33+
constexpr std::size_t height() const noexcept { return h; }
34+
constexpr std::size_t area() const noexcept { return w * h; }
2135

22-
void assert_not_empty(const char *where) const
23-
{
24-
if (empty())
25-
throw std::invalid_argument(std::string(where) + ": image is empty");
26-
}
27-
};
36+
void assert_not_empty(const char *where) const
37+
{
38+
if (empty())
39+
throw std::invalid_argument(std::string(where) + ": image is empty");
40+
}
41+
};
2842

2943
} // namespace vix::ai::vision
44+
45+
#endif

include/vix/ai/vision/OCR.hpp

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
#pragma once
1+
/**
2+
* @file OCR.hpp
3+
* @author Gaspard Kirira
4+
*
5+
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* https://github.com/vixcpp/vix
7+
* Use of this source code is governed by a MIT license that can be found in the License file.
8+
*
9+
* Vix.cpp
10+
*/
11+
#ifndef VIX_AI_VISION_OCR_HPP
12+
#define VIX_AI_VISION_OCR_HPP
13+
214
#include <string>
3-
#include "Image.hpp"
15+
#include <vix/ai/vision/Image.hpp>
416

517
namespace vix::ai::vision
618
{
7-
8-
struct OCR
19+
struct OCR
20+
{
21+
std::string recognize(const Image &img) const
922
{
10-
// v0 stub: returns empty string, but validates image
11-
std::string recognize(const Image &img) const
12-
{
13-
img.assert_not_empty("OCR::recognize");
14-
return {};
15-
}
16-
};
23+
img.assert_not_empty("OCR::recognize");
24+
return {};
25+
}
26+
};
1727

1828
} // namespace vix::ai::vision
29+
30+
#endif

include/vix/ai/vision/Tracker.hpp

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,33 @@
1-
#pragma once
1+
/**
2+
* @file Tracker.hpp
3+
* @author Gaspard Kirira
4+
*
5+
* Copyright 2025, Gaspard Kirira. All rights reserved.
6+
* https://github.com/vixcpp/vix
7+
* Use of this source code is governed by a MIT license that can be found in the License file.
8+
*
9+
* Vix.cpp
10+
*/
11+
#ifnde VIX_AI_VISION_TRACKER_HPP
12+
#define VIX_AI_VISION_TRACKER_HPP
13+
214
#include <cstddef>
3-
#include "Image.hpp"
15+
#include <vix/ai/vision/Image.hpp>
416

517
namespace vix::ai::vision
618
{
7-
8-
struct Tracker
19+
struct Tracker
20+
{
21+
std::size_t update(const Image &img)
922
{
10-
// v0 stub: returns incrementing pseudo-frame id to show statefulness later
11-
std::size_t update(const Image &img)
12-
{
13-
img.assert_not_empty("Tracker::update");
14-
return ++frames_;
15-
}
23+
img.assert_not_empty("Tracker::update");
24+
return ++frames_;
25+
}
1626

17-
private:
18-
std::size_t frames_{0};
19-
};
27+
private:
28+
std::size_t frames_{0};
29+
};
2030

2131
} // namespace vix::ai::vision
32+
33+
#endif

src/Detector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#include "vix/ai/vision/Detector.hpp"
1+
#include <vix/ai/vision/Detector.hpp>

src/Image.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#include "vix/ai/vision/Image.hpp"
1+
#include <vix/ai/vision/Image.hpp>

src/OCR.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#include "vix/ai/vision/OCR.hpp"
1+
#include <vix/ai/vision/OCR.hpp>

src/Tracker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#include "vix/ai/vision/Tracker.hpp"
1+
#include <vix/ai/vision/Tracker.hpp>

tests/detector_tests.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ using namespace vix::ai::vision;
55

66
int main()
77
{
8-
Detector d;
8+
Detector d;
99

10-
// empty image should throw
11-
try
12-
{
13-
(void)d.detect(Image{});
14-
assert(false && "Expected throw");
15-
}
16-
catch (const std::invalid_argument &)
17-
{
18-
}
10+
// empty image should throw
11+
try
12+
{
13+
(void)d.detect(Image{});
14+
assert(false && "Expected throw");
15+
}
16+
catch (const std::invalid_argument &)
17+
{
18+
}
1919

20-
auto boxes = d.detect(Image{10, 10});
21-
assert(boxes.empty());
22-
(void)boxes;
23-
return 0;
20+
auto boxes = d.detect(Image{10, 10});
21+
assert(boxes.empty());
22+
(void)boxes;
23+
return 0;
2424
}

0 commit comments

Comments
 (0)