trainingsample 0.2.16__tar.gz → 0.2.18__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. {trainingsample-0.2.16 → trainingsample-0.2.18}/.github/workflows/ci.yml +95 -83
  2. {trainingsample-0.2.16 → trainingsample-0.2.18}/.github/workflows/publish.yml +6 -6
  3. trainingsample-0.2.18/BENCHMARKS.md +137 -0
  4. {trainingsample-0.2.16 → trainingsample-0.2.18}/Cargo.lock +353 -305
  5. {trainingsample-0.2.16 → trainingsample-0.2.18}/Cargo.toml +3 -2
  6. {trainingsample-0.2.16 → trainingsample-0.2.18}/PKG-INFO +1 -1
  7. trainingsample-0.2.18/README.md +180 -0
  8. trainingsample-0.2.18/docs/API_COMPAT_CV2.md +216 -0
  9. {trainingsample-0.2.16 → trainingsample-0.2.18}/docs/BUILDING_STATIC_OPENCV.md +13 -12
  10. {trainingsample-0.2.16 → trainingsample-0.2.18}/pyproject.toml +1 -1
  11. {trainingsample-0.2.16 → trainingsample-0.2.18}/rust-toolchain.toml +0 -1
  12. {trainingsample-0.2.16 → trainingsample-0.2.18}/scripts/build-opencv-static.sh +1 -1
  13. trainingsample-0.2.18/setup-env.sh +304 -0
  14. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/cv_compat.rs +54 -34
  15. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/luminance.rs +37 -33
  16. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/opencv_ops.rs +16 -7
  17. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/python_bindings.rs +68 -81
  18. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/tests.rs +166 -1
  19. {trainingsample-0.2.16 → trainingsample-0.2.18}/tests/test_performance_benchmarks.py +2 -1
  20. {trainingsample-0.2.16 → trainingsample-0.2.18}/tests/test_python_bindings.py +64 -1
  21. trainingsample-0.2.16/BENCHMARKS.md +0 -112
  22. trainingsample-0.2.16/README.md +0 -291
  23. trainingsample-0.2.16/docs/API_COMPAT_CV2.md +0 -357
  24. trainingsample-0.2.16/setup-env.sh +0 -34
  25. {trainingsample-0.2.16 → trainingsample-0.2.18}/.cargo/config.toml +0 -0
  26. {trainingsample-0.2.16 → trainingsample-0.2.18}/.envrc +0 -0
  27. {trainingsample-0.2.16 → trainingsample-0.2.18}/.gitignore +0 -0
  28. {trainingsample-0.2.16 → trainingsample-0.2.18}/.pre-commit-config.yaml +0 -0
  29. {trainingsample-0.2.16 → trainingsample-0.2.18}/.rustfmt.toml +0 -0
  30. {trainingsample-0.2.16 → trainingsample-0.2.18}/Dockerfile +0 -0
  31. {trainingsample-0.2.16 → trainingsample-0.2.18}/LICENSE +0 -0
  32. {trainingsample-0.2.16 → trainingsample-0.2.18}/clippy.toml +0 -0
  33. {trainingsample-0.2.16 → trainingsample-0.2.18}/scripts/repair-wheel.sh +0 -0
  34. {trainingsample-0.2.16 → trainingsample-0.2.18}/scripts/run_competitive_benchmarks.sh +0 -0
  35. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/core.rs +0 -0
  36. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/cropping.rs +0 -0
  37. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/cv_batch_ops.rs +0 -0
  38. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/cv_batch_ops_optimized.rs +0 -0
  39. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/format_conversion_simd.rs +0 -0
  40. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/lib.rs +0 -0
  41. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/loading.rs +0 -0
  42. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/luminance_simd.rs +0 -0
  43. {trainingsample-0.2.16 → trainingsample-0.2.18}/src/true_batch_ops.rs +0 -0
  44. {trainingsample-0.2.16 → trainingsample-0.2.18}/tests/__init__.py +0 -0
  45. {trainingsample-0.2.16 → trainingsample-0.2.18}/tests/comprehensive_tests.rs +0 -0
  46. {trainingsample-0.2.16 → trainingsample-0.2.18}/tests/test_comprehensive.py +0 -0
@@ -32,12 +32,12 @@ jobs:
32
32
  ls -la /usr/lib/llvm-18/lib/libclang.so
33
33
  which llvm-config-18
34
34
 
35
- # Build OpenCV 4.12 from source since Ubuntu 24.04 only has 4.6
36
- echo "Building OpenCV 4.12 from source..."
35
+ # Build OpenCV 4.11 from source since Ubuntu 24.04 only has 4.6
36
+ echo "Building OpenCV 4.11 from source..."
37
37
  cd /tmp
38
- wget -q https://github.com/opencv/opencv/archive/4.12.0.tar.gz
39
- tar -xzf 4.12.0.tar.gz
40
- cd opencv-4.12.0
38
+ wget -q https://github.com/opencv/opencv/archive/4.11.0.tar.gz
39
+ tar -xzf 4.11.0.tar.gz
40
+ cd opencv-4.11.0
41
41
  mkdir build
42
42
  cd build
43
43
  cmake \
@@ -127,12 +127,12 @@ jobs:
127
127
  ls -la /usr/lib/llvm-18/lib/libclang.so
128
128
  which llvm-config-18
129
129
 
130
- # Build OpenCV 4.12 from source since Ubuntu 24.04 only has 4.6
131
- echo "Building OpenCV 4.12 from source..."
130
+ # Build OpenCV 4.11 from source since Ubuntu 24.04 only has 4.6
131
+ echo "Building OpenCV 4.11 from source..."
132
132
  cd /tmp
133
- wget -q https://github.com/opencv/opencv/archive/4.12.0.tar.gz
134
- tar -xzf 4.12.0.tar.gz
135
- cd opencv-4.12.0
133
+ wget -q https://github.com/opencv/opencv/archive/4.11.0.tar.gz
134
+ tar -xzf 4.11.0.tar.gz
135
+ cd opencv-4.11.0
136
136
  mkdir build
137
137
  cd build
138
138
  cmake \
@@ -218,12 +218,12 @@ jobs:
218
218
  ls -la /usr/lib/llvm-18/lib/libclang.so
219
219
  which llvm-config-18
220
220
 
221
- # Build OpenCV 4.12 from source since Ubuntu 24.04 only has 4.6
222
- echo "Building OpenCV 4.12 from source..."
221
+ # Build OpenCV 4.11 from source since Ubuntu 24.04 only has 4.6
222
+ echo "Building OpenCV 4.11 from source..."
223
223
  cd /tmp
224
- wget -q https://github.com/opencv/opencv/archive/4.12.0.tar.gz
225
- tar -xzf 4.12.0.tar.gz
226
- cd opencv-4.12.0
224
+ wget -q https://github.com/opencv/opencv/archive/4.11.0.tar.gz
225
+ tar -xzf 4.11.0.tar.gz
226
+ cd opencv-4.11.0
227
227
  mkdir build
228
228
  cd build
229
229
  cmake \
@@ -265,7 +265,7 @@ jobs:
265
265
  components: rustfmt, clippy
266
266
 
267
267
  - name: Install cargo-audit
268
- run: cargo install cargo-audit
268
+ run: cargo install cargo-audit --version 0.22.2 --locked
269
269
 
270
270
  - name: Install pre-commit
271
271
  run: pip install pre-commit
@@ -298,12 +298,12 @@ jobs:
298
298
  ls -la /usr/lib/llvm-18/lib/libclang.so
299
299
  which llvm-config-18
300
300
 
301
- # Build OpenCV 4.12 from source since Ubuntu 24.04 only has 4.6
302
- echo "Building OpenCV 4.12 from source..."
301
+ # Build OpenCV 4.11 from source since Ubuntu 24.04 only has 4.6
302
+ echo "Building OpenCV 4.11 from source..."
303
303
  cd /tmp
304
- wget -q https://github.com/opencv/opencv/archive/4.12.0.tar.gz
305
- tar -xzf 4.12.0.tar.gz
306
- cd opencv-4.12.0
304
+ wget -q https://github.com/opencv/opencv/archive/4.11.0.tar.gz
305
+ tar -xzf 4.11.0.tar.gz
306
+ cd opencv-4.11.0
307
307
  mkdir build
308
308
  cd build
309
309
  cmake \
@@ -348,19 +348,19 @@ jobs:
348
348
  - name: Install maturin (Linux/macOS)
349
349
  run: pip install maturin[patchelf]
350
350
 
351
- - name: Install OpenCV (macOS)
351
+ - name: Install OpenCV build dependencies (macOS)
352
352
  if: runner.os == 'macOS'
353
353
  run: |
354
- # Install OpenCV and LLVM via Homebrew
355
- brew install opencv llvm
354
+ # Build against a pinned OpenCV version instead of Homebrew's moving target
355
+ brew install llvm cmake nasm pkg-config
356
356
  # Set up LLVM environment for opencv-rust bindings (keg-only installation)
357
357
  echo "LIBCLANG_PATH=/opt/homebrew/opt/llvm/lib" >> $GITHUB_ENV
358
358
  echo "LLVM_CONFIG_PATH=/opt/homebrew/opt/llvm/bin/llvm-config" >> $GITHUB_ENV
359
359
  echo "DYLD_LIBRARY_PATH=/opt/homebrew/opt/llvm/lib:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV
360
- # Set up OpenCV environment
361
- echo "OPENCV_LINK_LIBS=opencv_calib3d,opencv_core,opencv_dnn,opencv_features2d,opencv_flann,opencv_highgui,opencv_imgcodecs,opencv_imgproc,opencv_ml,opencv_objdetect,opencv_photo,opencv_stitching,opencv_video,opencv_videoio" >> $GITHUB_ENV
362
- echo "OPENCV_LINK_PATHS=/opt/homebrew/lib" >> $GITHUB_ENV
363
- echo "OPENCV_INCLUDE_PATHS=/opt/homebrew/include/opencv4" >> $GITHUB_ENV
360
+
361
+ - name: Build static OpenCV (macOS)
362
+ if: runner.os == 'macOS'
363
+ run: ./scripts/build-opencv-static.sh
364
364
 
365
365
  - name: Build wheels (Linux)
366
366
  if: runner.os == 'Linux'
@@ -369,6 +369,11 @@ jobs:
369
369
  - name: Build wheels (macOS)
370
370
  if: runner.os == 'macOS'
371
371
  run: maturin build --release --out dist --no-default-features --features python-bindings,simd,opencv,metal
372
+ env:
373
+ OPENCV_INCLUDE_PATHS: ${{ github.workspace }}/third_party/opencv-static/include/opencv4
374
+ OPENCV_LINK_PATHS: ${{ github.workspace }}/third_party/opencv-static/lib
375
+ OPENCV_LINK_LIBS: static=opencv_world,static=avformat,static=avcodec,static=avfilter,static=swresample,static=swscale,static=avutil,static=jpeg,static=png,static=tiff,static=webp,static=jasper,framework=Accelerate,dylib=c++,framework=OpenCL,z
376
+ OPENCV_DISABLE_PROBES: pkg_config,cmake,vcpkg,vcpkg_cmake
372
377
 
373
378
 
374
379
  - name: Upload wheels
@@ -378,79 +383,86 @@ jobs:
378
383
  path: dist/
379
384
 
380
385
  build-wheels-aarch64:
381
- name: Build wheels (Linux aarch64)
386
+ name: Build wheels (Linux aarch64 / DGX Spark)
382
387
  runs-on: ubuntu-24.04-arm
383
388
  strategy:
384
389
  matrix:
385
- python-version: ["3.11", "3.12", "3.13"]
390
+ python: ["3.11", "3.12", "3.13"]
386
391
 
387
392
  steps:
388
393
  - uses: actions/checkout@v4
389
394
 
390
- - name: Install OpenCV and LLVM dependencies
395
+ - name: Set up Python ${{ matrix.python }}
396
+ uses: actions/setup-python@v5
397
+ with:
398
+ python-version: ${{ matrix.python }}
399
+
400
+ - name: Cache static OpenCV
401
+ uses: actions/cache@v4
402
+ with:
403
+ path: third_party/opencv-static
404
+ key: opencv-static-4.11.0-codecs-jasper-ffmpeg-no-itt-no-openjpeg-linux-aarch64-${{ runner.arch }}-manylinux_2_39
405
+
406
+ - name: Install build dependencies
391
407
  run: |
408
+ export DEBIAN_FRONTEND=noninteractive
409
+
392
410
  sudo apt-get update
393
- sudo apt-get install -y pkg-config clang libclang-dev llvm-dev wget cmake build-essential
394
- # Install LLVM 18 which has the proper libclang.so symlink
411
+ sudo apt-get install -y pkg-config clang libclang-dev llvm-dev wget cmake build-essential curl nasm yasm
412
+
395
413
  sudo apt-get install -y llvm-18 llvm-18-dev llvm-18-tools libclang1-18 libclang-cpp18
396
- # Set environment variables for LLVM 18
397
- echo "LIBCLANG_PATH=/usr/lib/llvm-18/lib" >> $GITHUB_ENV
398
414
  echo "LLVM_CONFIG_PATH=/usr/bin/llvm-config-18" >> $GITHUB_ENV
399
- echo "LD_LIBRARY_PATH=/usr/lib/llvm-18/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
400
-
401
- # Build OpenCV 4.12 from source
402
- echo "Building OpenCV 4.12 from source..."
403
- cd /tmp
404
- wget -q https://github.com/opencv/opencv/archive/4.12.0.tar.gz
405
- tar -xzf 4.12.0.tar.gz
406
- cd opencv-4.12.0
407
- mkdir build
408
- cd build
409
- cmake \
410
- -DCMAKE_BUILD_TYPE=RELEASE \
411
- -DCMAKE_INSTALL_PREFIX=/usr/local \
412
- -DWITH_CUDA=OFF \
413
- -DWITH_OPENGL=OFF \
414
- -DWITH_OPENCL=OFF \
415
- -DWITH_TBB=OFF \
416
- -DWITH_IPP=OFF \
417
- -DWITH_1394=OFF \
418
- -DWITH_V4L=OFF \
419
- -DWITH_GTK=OFF \
420
- -DBUILD_TESTS=OFF \
421
- -DBUILD_PERF_TESTS=OFF \
422
- -DBUILD_EXAMPLES=OFF \
423
- -DBUILD_opencv_python2=OFF \
424
- -DBUILD_opencv_python3=OFF \
425
- -DBUILD_opencv_java=OFF \
426
- -DOPENCV_GENERATE_PKGCONFIG=ON \
427
- ..
428
- make -j$(nproc)
429
- sudo make install
430
- sudo ldconfig
431
415
 
432
- # Set OpenCV environment variables
433
- echo "PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV
434
- echo "LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV
416
+ LIBCLANG_PATH="/usr/lib/llvm-18/lib"
417
+ if [ ! -f "$LIBCLANG_PATH/libclang.so" ]; then
418
+ LIBCLANG_PATH=$(find /usr/lib/llvm* -name "libclang.so" 2>/dev/null | head -1 | xargs dirname)
419
+ fi
435
420
 
436
- - name: Set up Python ${{ matrix.python-version }}
437
- uses: actions/setup-python@v4
438
- with:
439
- python-version: ${{ matrix.python-version }}
440
-
441
- - name: Install Rust toolchain
442
- uses: dtolnay/rust-toolchain@master
443
- with:
444
- toolchain: 1.89
421
+ echo "LIBCLANG_PATH=$LIBCLANG_PATH" >> $GITHUB_ENV
422
+ echo "LD_LIBRARY_PATH=$LIBCLANG_PATH:$LD_LIBRARY_PATH" >> $GITHUB_ENV
423
+ echo "Using libclang.so at: $LIBCLANG_PATH/libclang.so"
445
424
 
446
- - name: Install maturin
447
- run: pip install maturin[patchelf]
425
+ - name: Build static OpenCV
426
+ run: ./scripts/build-opencv-static.sh
448
427
 
449
428
  - name: Build wheels
450
- run: maturin build --release --out dist --no-default-features --features python-bindings,simd,opencv
429
+ uses: PyO3/maturin-action@v1
430
+ with:
431
+ target: aarch64
432
+ args: --release --out dist --no-default-features --features python-bindings,simd,opencv
433
+ sccache: 'false'
434
+ container: off
435
+ manylinux: manylinux_2_39
436
+ env:
437
+ PYO3_USE_ABI3_FORWARD_COMPATIBILITY: '1'
438
+ LIBCLANG_PATH: ${{ env.LIBCLANG_PATH }}
439
+ LLVM_CONFIG_PATH: ${{ env.LLVM_CONFIG_PATH }}
440
+ OPENCV_INCLUDE_PATHS: ${{ github.workspace }}/third_party/opencv-static/include/opencv4
441
+ OPENCV_LINK_PATHS: ${{ github.workspace }}/third_party/opencv-static/lib
442
+ OPENCV_LINK_LIBS: static=opencv_world,static=avformat,static=avcodec,static=avfilter,static=swresample,static=swscale,static=avutil,static=jpeg,static=png,static=tiff,static=webp,static=z,static=jasper,dylib=stdc++
443
+ OPENCV_DISABLE_PROBES: pkg_config,cmake,vcpkg,vcpkg_cmake
444
+
445
+ - name: Repair wheels
446
+ env:
447
+ OPENCV_LINK_PATHS: ${{ github.workspace }}/third_party/opencv-static/lib
448
+ run: ./scripts/repair-wheel.sh dist/*.whl
449
+
450
+ - name: Prune unrepaired wheels
451
+ run: find dist -type f -name '*.linux_*.whl' -print -delete
452
+
453
+ - name: Install built wheel
454
+ run: |
455
+ wheel="$(find dist -type f -name '*.whl' | sort | head -n 1)"
456
+ if [ -z "${wheel}" ]; then
457
+ echo "No wheel files found under dist/"
458
+ find dist -maxdepth 3 -type f || true
459
+ exit 1
460
+ fi
461
+ pip install "${wheel}"
462
+ python -c 'import trainingsample'
451
463
 
452
464
  - name: Upload wheels
453
465
  uses: actions/upload-artifact@v4
454
466
  with:
455
- name: wheels-linux-aarch64-py${{ matrix.python-version }}
467
+ name: wheels-linux-aarch64-py${{ matrix.python }}
456
468
  path: dist/
@@ -49,7 +49,7 @@ jobs:
49
49
  uses: actions/cache@v4
50
50
  with:
51
51
  path: third_party/opencv-static
52
- key: opencv-static-4.12.0-codecs-jasper-ffmpeg-no-itt-no-openjpeg-linux-${{ matrix.os }}-${{ runner.arch }}-${{ matrix.manylinux }}
52
+ key: opencv-static-4.11.0-codecs-jasper-ffmpeg-no-itt-no-openjpeg-linux-${{ matrix.os }}-${{ runner.arch }}-${{ matrix.manylinux }}
53
53
 
54
54
  - name: Install build dependencies
55
55
  run: |
@@ -112,7 +112,7 @@ jobs:
112
112
  # OpenCV static linking configuration
113
113
  OPENCV_INCLUDE_PATHS: ${{ github.workspace }}/third_party/opencv-static/include/opencv4
114
114
  OPENCV_LINK_PATHS: ${{ github.workspace }}/third_party/opencv-static/lib
115
- OPENCV_LINK_LIBS: static=opencv_world,static=avformat,static=avcodec,static=avfilter,static=swresample,static=swscale,static=avutil,static=jpeg,static=png,static=tiff,static=webp,static=z,static=jasper,static=stdc++
115
+ OPENCV_LINK_LIBS: static=opencv_world,static=avformat,static=avcodec,static=avfilter,static=swresample,static=swscale,static=avutil,static=jpeg,static=png,static=tiff,static=webp,static=z,static=jasper,dylib=stdc++
116
116
  OPENCV_DISABLE_PROBES: pkg_config,cmake,vcpkg,vcpkg_cmake
117
117
 
118
118
  - name: Repair wheels
@@ -147,7 +147,7 @@ jobs:
147
147
  uses: actions/cache@v4
148
148
  with:
149
149
  path: third_party/opencv-static
150
- key: opencv-static-4.12.0-codecs-jasper-ffmpeg-no-itt-no-openjpeg-linux-aarch64-${{ runner.arch }}-manylinux_2_39
150
+ key: opencv-static-4.11.0-codecs-jasper-ffmpeg-no-itt-no-openjpeg-linux-aarch64-${{ runner.arch }}-manylinux_2_39
151
151
 
152
152
  - name: Install build dependencies
153
153
  run: |
@@ -194,7 +194,7 @@ jobs:
194
194
  # OpenCV static linking configuration
195
195
  OPENCV_INCLUDE_PATHS: ${{ github.workspace }}/third_party/opencv-static/include/opencv4
196
196
  OPENCV_LINK_PATHS: ${{ github.workspace }}/third_party/opencv-static/lib
197
- OPENCV_LINK_LIBS: static=opencv_world,static=avformat,static=avcodec,static=avfilter,static=swresample,static=swscale,static=avutil,static=jpeg,static=png,static=tiff,static=webp,static=z,static=jasper,static=stdc++
197
+ OPENCV_LINK_LIBS: static=opencv_world,static=avformat,static=avcodec,static=avfilter,static=swresample,static=swscale,static=avutil,static=jpeg,static=png,static=tiff,static=webp,static=z,static=jasper,dylib=stdc++
198
198
  OPENCV_DISABLE_PROBES: pkg_config,cmake,vcpkg,vcpkg_cmake
199
199
 
200
200
  - name: Repair wheels
@@ -229,7 +229,7 @@ jobs:
229
229
  uses: actions/cache@v4
230
230
  with:
231
231
  path: third_party/opencv-static
232
- key: opencv-static-4.12.0-codecs-jasper-ffmpeg-no-itt-no-openjpeg-macos-${{ runner.os }}-${{ runner.arch }}
232
+ key: opencv-static-4.11.0-codecs-jasper-ffmpeg-no-itt-no-openjpeg-macos-${{ runner.os }}-${{ runner.arch }}
233
233
 
234
234
  - name: Install build dependencies
235
235
  run: |
@@ -372,7 +372,7 @@ jobs:
372
372
  fi
373
373
  echo "Installing wheel: ${wheel}"
374
374
  pip install "${wheel}"
375
- python -c 'import trainingsample' || echo "Import failed"
375
+ python -c 'import trainingsample'
376
376
 
377
377
  release:
378
378
  name: Release
@@ -0,0 +1,137 @@
1
+ # Performance Benchmarks
2
+
3
+ TrainingSample includes benchmarks for common preprocessing operations: crop, resize, luminance, resize-plus-luminance pipelines, and video frame resizing. The benchmarks are meant to catch regressions and provide workload-specific guidance, not to guarantee universal speedups over OpenCV or NumPy.
4
+
5
+ ## Running Benchmarks
6
+
7
+ Use the repository virtual environment when available:
8
+
9
+ ```bash
10
+ .venv/bin/python -m pytest tests/test_performance_benchmarks.py -q -s
11
+ ```
12
+
13
+ To run every Python test and benchmark marker in the repo:
14
+
15
+ ```bash
16
+ .venv/bin/python -m pytest -q
17
+ ```
18
+
19
+ For a fresh source build before measuring:
20
+
21
+ ```bash
22
+ env -u OPENCV_LINK_LIBS -u OPENCV_LINK_PATHS -u OPENCV_INCLUDE_PATHS \
23
+ -u LIBCLANG_PATH -u LLVM_CONFIG_PATH \
24
+ .venv/bin/maturin develop --release
25
+ ```
26
+
27
+ The OpenCV Rust binding needs a discoverable OpenCV and Clang installation. On this development host, stale macOS-style OpenCV and LLVM environment variables had to be unset before the build could probe the system OpenCV installation.
28
+
29
+ ## Current Local Snapshot
30
+
31
+ Last measured command:
32
+
33
+ ```bash
34
+ .venv/bin/python -m pytest tests/test_performance_benchmarks.py -q -s
35
+ ```
36
+
37
+ Environment:
38
+
39
+ - Linux x86_64
40
+ - CPython 3.13
41
+ - NumPy 2.3.4
42
+ - system OpenCV 4.11 via the Rust `opencv` crate
43
+ - release build installed with `maturin develop --release`
44
+
45
+ Point-in-time scenario timings from the benchmark output:
46
+
47
+ | Scenario | Before optimization | After optimization | Comparison after optimization |
48
+ |----------|---------------------|--------------------|-------------------------------|
49
+ | Crop batch, 16 images | 22.9 ms | 0.4 ms | NumPy slicing was still faster because it returns views |
50
+ | Mixed-shape crop, 8 images | 50.2 ms | 3.3 ms | NumPy slicing loop was near-zero because it returns views |
51
+ | Resize, 4 mixed-size images | 4.1 ms | 0.4 ms | OpenCV loop: 2.6 ms |
52
+ | Luminance, 4 mixed-size images | 10.4 ms | 0.6 ms | OpenCV loop: 0.9 ms |
53
+ | Resize + luminance pipeline, 4 images | 5.9 ms | 0.6 ms | OpenCV loop: 2.1 ms |
54
+ | Mixed-shape luminance, 6 images | 78.3 ms | 3.3 ms | NumPy loop: 19.4 ms |
55
+
56
+ Pytest-benchmark means from the same focused run:
57
+
58
+ | Benchmark | Mean |
59
+ |-----------|------|
60
+ | Center crop | 55.2 us |
61
+ | Resize operations | 353.1 us |
62
+ | Luminance calculation | 417.2 us |
63
+ | Crop operations | 583.8 us |
64
+ | Pipeline | 3.44 ms |
65
+ | Video processing | 2.85 ms |
66
+
67
+ A full `pytest -q` run also passed and produced similar benchmark ordering, with normal run-to-run variance.
68
+
69
+ ## What Changed in the Latest Optimization
70
+
71
+ - Owned Rust `ndarray` outputs are transferred into NumPy with `from_owned_array_bound`, avoiding an additional copy in Python-facing result conversion.
72
+ - Contiguous luminance inputs use a channel-sum fast path. Instead of computing weighted luminance per pixel, it sums R, G, and B separately and applies the weights once at the end.
73
+ - Non-contiguous arrays still use the general ndarray path for correctness.
74
+
75
+ ## Benchmark Categories
76
+
77
+ ### Image Operations
78
+
79
+ - `batch_crop_images`
80
+ - `batch_center_crop_images`
81
+ - `batch_random_crop_images`
82
+ - `batch_resize_images`
83
+ - `batch_calculate_luminance`
84
+
85
+ ### Pipeline Operations
86
+
87
+ - resize followed by luminance
88
+ - crop followed by resize
89
+ - mixed input sizes and output sizes
90
+
91
+ ### Video Operations
92
+
93
+ - `batch_resize_videos` with frame batches shaped `(T, H, W, 3)`
94
+
95
+ ## Interpreting Results
96
+
97
+ Use these benchmarks to answer practical questions:
98
+
99
+ - Is a change adding extra Rust-to-NumPy copies?
100
+ - Are contiguous arrays staying on the fast path?
101
+ - Is resize dominated by OpenCV work or Python binding overhead?
102
+ - Does a mixed-shape batch still behave reasonably?
103
+ - Is a video processing change accidentally introducing per-frame Python overhead?
104
+
105
+ Some comparisons need context:
106
+
107
+ - NumPy crop by slicing often returns a view, so it can be much faster than any function that returns owned cropped arrays.
108
+ - Very small images can be dominated by Python call overhead.
109
+ - Large images can be dominated by memory bandwidth rather than arithmetic.
110
+ - OpenCV performance varies by build options, CPU features, and linked libraries.
111
+
112
+ ## Quality Checks
113
+
114
+ The tests validate basic output behavior alongside timing:
115
+
116
+ - Crop outputs have expected shape and match NumPy slicing where ownership differences do not matter.
117
+ - Resize outputs have expected shape and are close to OpenCV output for the configured interpolation.
118
+ - Luminance stays within a small tolerance of NumPy/OpenCV-style references.
119
+ - Non-contiguous arrays are accepted by safe luminance paths and rejected by strict zero-copy crop/resize paths.
120
+
121
+ ## Regression Signals
122
+
123
+ Investigate if a change causes:
124
+
125
+ - Public batch crop to return to multi-millisecond timings for small batches.
126
+ - Luminance on contiguous RGB arrays to lose the channel-sum fast path.
127
+ - Resize benchmarks to add large overhead beyond OpenCV work.
128
+ - Video resizing to scale with per-frame Python object churn.
129
+ - Memory usage to grow unexpectedly for repeated batch calls.
130
+
131
+ ## Future Benchmark Work
132
+
133
+ - Store historical benchmark results by commit and host.
134
+ - Add explicit memory allocation tracking for Python-facing APIs.
135
+ - Separate view-returning crop comparisons from owned-output crop comparisons.
136
+ - Add more video pipeline benchmarks.
137
+ - Document hardware and OpenCV build details in benchmark artifacts.