Skip to content

Commit 9b95251

Browse files
committed
Merge branch 'dev'
2 parents 02e770f + 342d755 commit 9b95251

11 files changed

Lines changed: 217 additions & 59 deletions

File tree

CMakeLists.txt

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,67 @@
1-
add_library(vix_ai_vision
2-
src/Image.cpp
3-
src/Detector.cpp
4-
src/OCR.cpp
5-
src/Tracker.cpp
6-
)
1+
cmake_minimum_required(VERSION 3.20)
72

8-
add_library(Vix::AI::vision ALIAS vix_ai_vision)
3+
project(vix-ai-vision
4+
VERSION 0.1.0
5+
DESCRIPTION "Vix.AI Vision: image primitives, detector, tracker, OCR (header-only v0)"
6+
LANGUAGES CXX)
7+
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)
10+
option(VIX_AI_VISION_WARNINGS "Enable extra warnings" ON)
911

10-
target_link_libraries(vix_ai_vision PUBLIC Vix::AI::core Vix::AI::nn)
12+
add_library(vix_ai_vision INTERFACE)
13+
add_library(Vix::AI::vision ALIAS vix_ai_vision)
1114

12-
target_include_directories(vix_ai_vision PUBLIC
15+
target_include_directories(vix_ai_vision INTERFACE
1316
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
14-
$<INSTALL_INTERFACE:include>
15-
)
17+
$<INSTALL_INTERFACE:include>)
18+
19+
target_compile_features(vix_ai_vision INTERFACE cxx_std_20)
1620

17-
target_compile_features(vix_ai_vision PUBLIC cxx_std_20)
21+
if (DEFINED VIX_AI_VERSION)
22+
set(PROJECT_VERSION ${VIX_AI_VERSION})
23+
endif()
24+
target_compile_definitions(vix_ai_vision INTERFACE VIX_AI_VISION_VERSION="${PROJECT_VERSION}")
25+
26+
if (VIX_AI_VISION_WARNINGS)
27+
if (MSVC)
28+
target_compile_options(vix_ai_vision INTERFACE /W4 /permissive-)
29+
else()
30+
target_compile_options(vix_ai_vision INTERFACE -Wall -Wextra -Wpedantic)
31+
endif()
32+
endif()
1833

19-
option(VIX_AI_VISION_BUILD_TESTS "Build vix_ai_vision tests" ON)
34+
# Tests
2035
if (VIX_AI_VISION_BUILD_TESTS)
36+
enable_testing()
2137
add_subdirectory(tests)
2238
endif()
2339

24-
include(GNUInstallDirs)
25-
install(TARGETS vix_ai_vision EXPORT vix_ai_visionTargets
26-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
27-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
28-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
29-
)
30-
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
31-
install(EXPORT vix_ai_visionTargets FILE vix_ai_visionTargets.cmake NAMESPACE Vix::AI:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai_vision)
40+
# Install / package
41+
if (VIX_AI_VISION_INSTALL)
42+
include(GNUInstallDirs)
43+
include(CMakePackageConfigHelpers)
44+
45+
install(TARGETS vix_ai_vision
46+
EXPORT vix_ai_visionTargets)
47+
48+
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
49+
50+
install(EXPORT vix_ai_visionTargets
51+
FILE vix_ai_visionTargets.cmake
52+
NAMESPACE Vix::AI::
53+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai_vision)
54+
55+
write_basic_package_version_file(
56+
${CMAKE_CURRENT_BINARY_DIR}/vix_ai_visionConfigVersion.cmake
57+
VERSION ${PROJECT_VERSION}
58+
COMPATIBILITY SameMajorVersion)
59+
60+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/vix_ai_visionConfig.cmake
61+
"include(\"\${CMAKE_CURRENT_LIST_DIR}/vix_ai_visionTargets.cmake\")\n")
62+
63+
install(FILES
64+
${CMAKE_CURRENT_BINARY_DIR}/vix_ai_visionConfig.cmake
65+
${CMAKE_CURRENT_BINARY_DIR}/vix_ai_visionConfigVersion.cmake
66+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/vix_ai_vision)
67+
endif()

include/vix/ai/vision/Detector.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@
66
namespace vix::ai::vision
77
{
88

9+
// Bounding box: {x, y, w, h}
10+
using BBox = std::array<int, 4>;
11+
912
struct Detector
1013
{
11-
// renvoie N boxes factices: {x,y,w,h}
12-
std::vector<std::array<int, 4>> detect(const Image &) const { return {}; }
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+
}
1320
};
1421

15-
} // namespace vix::ai::vision
22+
} // namespace vix::ai::vision

include/vix/ai/vision/Image.hpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
#pragma once
22
#include <cstddef>
3-
#include <vector>
3+
#include <stdexcept>
4+
#include <string>
45

56
namespace vix::ai::vision
67
{
78

89
struct Image
910
{
10-
std::size_t w{};
11-
std::size_t h{}; // pas de pixels (squelette)
11+
std::size_t w{}; // width in pixels
12+
std::size_t h{}; // height in pixels
13+
14+
constexpr Image() = default;
15+
constexpr Image(std::size_t width, std::size_t height) : w(width), h(height) {}
16+
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; }
21+
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+
}
1227
};
1328

14-
} // namespace vix::ai::vision
29+
} // namespace vix::ai::vision

include/vix/ai/vision/OCR.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ namespace vix::ai::vision
77

88
struct OCR
99
{
10-
std::string recognize(const Image &) const { return {}; }
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+
}
1116
};
1217

13-
} // namespace vix::ai::vision
18+
} // namespace vix::ai::vision

include/vix/ai/vision/Tracker.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ namespace vix::ai::vision
77

88
struct Tracker
99
{
10-
std::size_t update(const Image &) { return 0; }
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+
}
16+
17+
private:
18+
std::size_t frames_{0};
1119
};
1220

13-
} // namespace vix::ai::vision
21+
} // namespace vix::ai::vision

tests/CMakeLists.txt

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1-
add_executable(vix_ai_vision_smoke_test vision_smoke_test.cpp)
2-
target_link_libraries(vix_ai_vision_smoke_test PRIVATE Vix::AI::vision)
3-
target_compile_features(vix_ai_vision_smoke_test PRIVATE cxx_std_20)
4-
add_test(NAME vix_ai_vision_smoke_test COMMAND vix_ai_vision_smoke_test)
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
#[[
4+
Vix.AI Vision — assert-based tests (header-only)
5+
]]
6+
7+
add_executable(vix_ai_vision_test_image image_tests.cpp)
8+
target_link_libraries(vix_ai_vision_test_image PRIVATE Vix::AI::vision)
9+
target_compile_features(vix_ai_vision_test_image PRIVATE cxx_std_20)
10+
add_test(NAME vision_image COMMAND vix_ai_vision_test_image)
11+
12+
add_executable(vix_ai_vision_test_detector detector_tests.cpp)
13+
target_link_libraries(vix_ai_vision_test_detector PRIVATE Vix::AI::vision)
14+
target_compile_features(vix_ai_vision_test_detector PRIVATE cxx_std_20)
15+
add_test(NAME vision_detector COMMAND vix_ai_vision_test_detector)
16+
17+
add_executable(vix_ai_vision_test_ocr ocr_tests.cpp)
18+
target_link_libraries(vix_ai_vision_test_ocr PRIVATE Vix::AI::vision)
19+
target_compile_features(vix_ai_vision_test_ocr PRIVATE cxx_std_20)
20+
add_test(NAME vision_ocr COMMAND vix_ai_vision_test_ocr)
21+
22+
add_executable(vix_ai_vision_test_tracker tracker_tests.cpp)
23+
target_link_libraries(vix_ai_vision_test_tracker PRIVATE Vix::AI::vision)
24+
target_compile_features(vix_ai_vision_test_tracker PRIVATE cxx_std_20)
25+
add_test(NAME vision_tracker COMMAND vix_ai_vision_test_tracker)

tests/detector_tests.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <cassert>
2+
#include <stdexcept>
3+
#include <vix/ai/vision/Detector.hpp>
4+
using namespace vix::ai::vision;
5+
6+
int main()
7+
{
8+
Detector d;
9+
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+
}
19+
20+
auto boxes = d.detect(Image{10, 10});
21+
assert(boxes.empty());
22+
(void)boxes;
23+
return 0;
24+
}

tests/image_tests.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <cassert>
2+
#include <vix/ai/vision/Image.hpp>
3+
using namespace vix::ai::vision;
4+
5+
int main()
6+
{
7+
Image e;
8+
(void)e;
9+
assert(e.empty());
10+
Image a(640, 480);
11+
assert(!a.empty());
12+
assert(a.width() == 640);
13+
assert(a.height() == 480);
14+
assert(a.area() == 640u * 480u);
15+
(void)a;
16+
return 0;
17+
}

tests/ocr_tests.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <cassert>
2+
#include <stdexcept>
3+
#include <vix/ai/vision/OCR.hpp>
4+
using namespace vix::ai::vision;
5+
6+
int main()
7+
{
8+
OCR ocr;
9+
10+
try
11+
{
12+
(void)ocr.recognize(Image{});
13+
assert(false && "Expected throw");
14+
}
15+
catch (const std::invalid_argument &)
16+
{
17+
}
18+
19+
auto txt = ocr.recognize(Image{32, 32});
20+
assert(txt.empty());
21+
(void)txt;
22+
return 0;
23+
}

tests/tracker_tests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <cassert>
2+
#include <stdexcept>
3+
#include <vix/ai/vision/Tracker.hpp>
4+
using namespace vix::ai::vision;
5+
6+
int main()
7+
{
8+
Tracker t;
9+
10+
try
11+
{
12+
(void)t.update(Image{});
13+
assert(false && "Expected throw");
14+
}
15+
catch (const std::invalid_argument &)
16+
{
17+
}
18+
19+
auto f1 = t.update(Image{4, 4});
20+
auto f2 = t.update(Image{4, 4});
21+
assert(f1 == 1 && f2 == 2);
22+
(void)f1;
23+
(void)f2;
24+
return 0;
25+
}

0 commit comments

Comments
 (0)