Skip to content

Commit ea9e0cf

Browse files
CVML CI Tests (#257)
* CVML CI Tests * Adding OpenCV_DIR path * Added opencv.md and OpenCV_DIR tests * Removing temp dir in Linux * Set openCV_DIR * Adding Linux OS * Adding env variables inside the test * Disabling Linux platform --------- Co-authored-by: Daniel Holanda <holand.daniel@gmail.com>
1 parent 82313c0 commit ea9e0cf

4 files changed

Lines changed: 371 additions & 1 deletion

File tree

playbooks/dependencies/opencv.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!--
2+
Copyright Advanced Micro Devices, Inc.
3+
4+
SPDX-License-Identifier: MIT
5+
-->
6+
7+
### OpenCV 4.11.0
8+
9+
**1. Install build dependencies**
10+
```bash
11+
sudo apt update
12+
sudo apt install -y build-essential cmake git pkg-config unzip wget
13+
sudo apt install -y libgtk-3-dev libavcodec-dev libavformat-dev libswscale-dev
14+
sudo apt install -y libjpeg-dev libpng-dev libtiff-dev
15+
```
16+
17+
**2. Download OpenCV 4.11.0 source**
18+
```bash
19+
cd /tmp
20+
wget -O opencv-4.11.0.zip https://github.com/opencv/opencv/archive/refs/tags/4.11.0.zip
21+
unzip opencv-4.11.0.zip
22+
```
23+
24+
**3. Configure build**
25+
```bash
26+
cd /tmp/opencv-4.11.0
27+
mkdir build
28+
cd build
29+
30+
cmake -S .. -B . \
31+
-DCMAKE_BUILD_TYPE=Release \
32+
-DCMAKE_INSTALL_PREFIX=/opt/opencv-4.11.0 \
33+
-DBUILD_opencv_python3=OFF \
34+
-DBUILD_opencv_python2=OFF \
35+
-DBUILD_TESTS=OFF \
36+
-DBUILD_PERF_TESTS=OFF \
37+
-DBUILD_EXAMPLES=OFF
38+
```
39+
40+
**4. Build and install**
41+
```bash
42+
cmake --build . --parallel "$(nproc)"
43+
sudo cmake --install .
44+
```
45+
46+
**5. Set OPENCV_INSTALL_ROOT permanently for interactive shells**
47+
```bash
48+
echo 'export OPENCV_INSTALL_ROOT=/opt/opencv-4.11.0' >> ~/.bashrc
49+
source ~/.bashrc
50+
```
51+
52+
Verify:
53+
```bash
54+
echo $OPENCV_INSTALL_ROOT
55+
ls $OPENCV_INSTALL_ROOT
56+
```
57+
58+
You should see folders like:
59+
- bin
60+
- include
61+
- Lib
62+
- share
63+
or similar.
64+
65+
**6. Set OpenCV_DIR permanently for interactive shells**
66+
`OpenCV_DIR` should point to the folder containing `OpenCVConfig.cmake`.
67+
```bash
68+
echo 'export OpenCV_DIR=/opt/opencv-4.11.0/lib/cmake/opencv4' >> ~/.bashrc
69+
source ~/.bashrc
70+
```
71+
72+
**7. System library path setup**
73+
If the sample executable cannot find OpenCV shared libraries at runtime, add:
74+
```bash
75+
export LD_LIBRARY_PATH=/opt/opencv-4.11.0/lib:$LD_LIBRARY_PATH
76+
```
77+

playbooks/dependencies/registry.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
"windows": ["halo_box"]
2525
}
2626
},
27+
"opencv": {
28+
"name": "OpenCV",
29+
"description": "Computer Vision library and framework",
30+
"category": "framework",
31+
"platforms": ["windows", "linux"],
32+
"file": "opencv.md",
33+
"preinstalled": {
34+
"linux": ["halo_box"],
35+
"windows": ["halo_box"]
36+
}
37+
},
2738
"lmstudio": {
2839
"name": "LM Studio",
2940
"description": "Desktop app for running local LLMs",

playbooks/supplemental/cvml/README.md

Lines changed: 273 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ This playbook teaches you how to set up the Ryzen AI CVML Library, build the inc
3232

3333
Before starting, ensure you have the following:
3434

35-
- [OpenCV 4.11](https://opencv.org/) downloaded and available on your system
3635
- CMake installed and available in your system PATH
3736

3837
<!-- @os:windows -->
38+
- [OpenCV 4.11](https://opencv.org/) downloaded and available on your system
3939
- [Ryzen AI NPU driver](https://ryzenai.docs.amd.com/en/latest/inst.html) (Windows installer)
4040
- [Visual Studio 2022](https://visualstudio.microsoft.com/) with the "Desktop development with C++" workload (includes MSVC compiler, Windows SDK, and C++ build tools)
4141
<!-- @os:end -->
@@ -44,6 +44,93 @@ Before starting, ensure you have the following:
4444
- Ubuntu 22.04 or 24.04 (kernel >= 6.11.0-21-generic)
4545
- [Ryzen AI NPU driver](https://ryzenai.docs.amd.com/en/1.6.1/linux.html#install-npu-drivers) (Linux installer — required for NPU inference)
4646
- Vulkan SDK (installed in the [Linux-Specific Setup](#linux-specific-setup) section below)
47+
<!-- @require:opencv -->
48+
<!-- @os:end -->
49+
50+
<!-- @os:linux -->
51+
<!-- @test:id=linux-runner-check timeout=120 hidden=True -->
52+
```bash
53+
cat /etc/os-release
54+
uname -r
55+
```
56+
<!-- @test:end -->
57+
<!-- @os:end -->
58+
59+
<!-- @os:windows -->
60+
<!-- @test:id=cvml-prereqs-windows timeout=120 hidden=True -->
61+
```powershell
62+
$ErrorActionPreference = "Stop"
63+
64+
git --version
65+
git lfs version
66+
cmake --version
67+
68+
if (-not $env:OPENCV_INSTALL_ROOT) {throw "OPENCV_INSTALL_ROOT is not set. Set it to your OpenCV 4.11 installation root before running this test."}
69+
if (-not (Test-Path $env:OPENCV_INSTALL_ROOT)) {throw "OPENCV_INSTALL_ROOT does not exist: $env:OPENCV_INSTALL_ROOT"}
70+
71+
if (-not $env:OpenCV_DIR) {throw "OpenCV_DIR is not set. Set it to point to the folder containing OpenCVConfig.cmake before running this test."}
72+
if (-not (Test-Path $env:OpenCV_DIR)) {throw "OpenCV_DIR does not exist: $env:OpenCV_DIR"}
73+
74+
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
75+
if (-not (Test-Path $vswhere)) {throw "vswhere.exe not found. Install Visual Studio 2022 with Desktop development with C++ workload."}
76+
77+
$vsInstall = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Workload.NativeDesktop -property installationPath
78+
if (-not $vsInstall) {throw "Visual Studio 2022 Desktop development with C++ workload was not found."}
79+
80+
$clPath = Get-ChildItem "$vsInstall\VC\Tools\MSVC" -Recurse -Filter cl.exe -ErrorAction SilentlyContinue | Select-Object -First 1
81+
if (-not $clPath) {throw "MSVC cl.exe was not found under Visual Studio installation."}
82+
```
83+
<!-- @test:end -->
84+
<!-- @os:end -->
85+
86+
<!-- @os:linux -->
87+
<!-- @test:id=cvml-prereqs-linux timeout=120 hidden=True -->
88+
```bash
89+
set -euo pipefail
90+
91+
export OPENCV_INSTALL_ROOT="${OPENCV_INSTALL_ROOT:-/opt/opencv-4.11.0}"
92+
export OpenCV_DIR="${OpenCV_DIR:-/opt/opencv-4.11.0/lib/cmake/opencv4}"
93+
94+
git --version
95+
git lfs version
96+
cmake --version
97+
98+
. /etc/os-release
99+
if [ "${VERSION_ID}" != "24.04" ]; then
100+
echo "This CI runner is expected to be Ubuntu 24.04. Found: ${PRETTY_NAME}"
101+
exit 1
102+
fi
103+
104+
if [ -z "${OPENCV_INSTALL_ROOT:-}" ]; then
105+
echo "OPENCV_INSTALL_ROOT is not set. Set it to your OpenCV 4.11 installation root before running this test."
106+
exit 1
107+
fi
108+
if [ ! -d "$OPENCV_INSTALL_ROOT" ]; then
109+
echo "OPENCV_INSTALL_ROOT does not exist: $OPENCV_INSTALL_ROOT"
110+
exit 1
111+
fi
112+
113+
if [ -z "${OpenCV_DIR:-}" ]; then
114+
echo "OpenCV_DIR is not set. Set it to point to the folder containing OpenCVConfig.cmake before running this test."
115+
exit 1
116+
fi
117+
if [ ! -d "$OpenCV_DIR" ]; then
118+
echo "OpenCV_DIR does not exist: $OpenCV_DIR"
119+
exit 1
120+
fi
121+
122+
if ! command -v glslc >/dev/null 2>&1 && ! command -v vulkaninfo >/dev/null 2>&1; then
123+
echo "Vulkan SDK tools were not found. Install the Vulkan SDK before running this test."
124+
exit 1
125+
fi
126+
127+
if [ ! -d /opt/xilinx/xrt/lib ]; then
128+
echo "/opt/xilinx/xrt/lib was not found. Install the Ryzen AI Linux NPU driver/XRT runtime before running this test."
129+
exit 1
130+
fi
131+
132+
```
133+
<!-- @test:end -->
47134
<!-- @os:end -->
48135

49136
## Setting Up the CVML Library
@@ -296,6 +383,191 @@ The face detection feature offers two model variants:
296383
| `fast` (default) | Higher FPS | Good | Real-time camera applications |
297384
| `precise` | Lower FPS | Best | Photo analysis, high-accuracy needs |
298385

386+
<!-- @os:windows -->
387+
<!-- @test:id=cvml-build-and-face-detection-windows timeout=1800 hidden=True -->
388+
```powershell
389+
$ErrorActionPreference = "Stop"
390+
391+
$playbookRoot = (Get-Location).Path
392+
393+
if (-not $env:OPENCV_INSTALL_ROOT) {throw "OPENCV_INSTALL_ROOT is not set."}
394+
if (-not $env:OpenCV_DIR) {throw "OpenCV_DIR is not set."}
395+
396+
$work = Join-Path (Get-Location) "cvml-test"
397+
New-Item -ItemType Directory -Force -Path $work | Out-Null
398+
399+
try {
400+
$repo = Join-Path $work "RyzenAI-SW"
401+
402+
git lfs install
403+
git clone --depth 1 https://github.com/amd/RyzenAI-SW.git $repo
404+
405+
Push-Location $repo
406+
git lfs pull
407+
Pop-Location
408+
409+
$cvmlRoot = Join-Path $repo "Ryzen-AI-CVML-Library"
410+
if (-not (Test-Path $cvmlRoot)) {throw "Ryzen-AI-CVML-Library folder was not found after cloning RyzenAI-SW."}
411+
412+
$lfsCandidate = Get-ChildItem (Join-Path $cvmlRoot "windows") -Recurse -Include *.dll,*.lib,*.amodel,*.graphlib -ErrorAction SilentlyContinue | Select-Object -First 1
413+
if (-not $lfsCandidate) {throw "No Windows CVML binary/runtime files were found. Git LFS may not have pulled the assets."}
414+
415+
$firstLine = Get-Content -Path $lfsCandidate.FullName -TotalCount 1 -ErrorAction SilentlyContinue
416+
if ($firstLine -like "version https://git-lfs.github.com/spec*") {throw "Git LFS file was downloaded as a pointer instead of the real binary: $($lfsCandidate.FullName)"}
417+
418+
$samplesDir = Join-Path $cvmlRoot "samples"
419+
$buildDir = Join-Path $samplesDir "build"
420+
421+
cmake -S $samplesDir -B $buildDir -DOPENCV_INSTALL_ROOT="$env:OPENCV_INSTALL_ROOT" -DOpenCV_DIR="$env:OpenCV_DIR"
422+
cmake --build $buildDir --config Release --parallel
423+
424+
$faceExe = Join-Path $buildDir "cvml-sample-face-detection\Release\cvml-sample-face-detection.exe"
425+
$depthExe = Join-Path $buildDir "cvml-sample-depth-estimation\Release\cvml-sample-depth-estimation.exe"
426+
$meshExe = Join-Path $buildDir "cvml-sample-face-mesh\Release\cvml-sample-face-mesh.exe"
427+
428+
foreach ($exe in @($faceExe, $depthExe, $meshExe)) {
429+
if (-not (Test-Path $exe)) {throw "Expected executable was not found: $exe"}
430+
}
431+
432+
$opencvBinCandidates = @(
433+
(Join-Path $env:OPENCV_INSTALL_ROOT "build\x64\vc16\bin"),
434+
(Join-Path $env:OPENCV_INSTALL_ROOT "x64\vc16\bin"),
435+
(Join-Path $env:OPENCV_INSTALL_ROOT "bin")
436+
) | Where-Object { Test-Path $_ }
437+
438+
foreach ($dir in $opencvBinCandidates) {
439+
$env:PATH = "$dir;$env:PATH"
440+
}
441+
442+
$env:PATH = "$(Join-Path $cvmlRoot "windows");$env:PATH"
443+
444+
$inputImage = Join-Path $playbookRoot "sample_face.jpg"
445+
if (-not (Test-Path $inputImage)) {
446+
$inputImage = Join-Path $work "sample_face.jpg"
447+
curl.exe -L -o $inputImage "https://images.pexels.com/photos/895863/pexels-photo-895863.jpeg?cs=srgb&dl=pexels-jopwell-895863.jpg&fm=jpg"
448+
}
449+
450+
$outputFast = Join-Path $work "output_face_fast.jpg"
451+
$outputPrecise = Join-Path $work "output_face_precise.jpg"
452+
453+
Push-Location (Split-Path $faceExe)
454+
& $faceExe -i $inputImage -o $outputFast
455+
if ($LASTEXITCODE -ne 0) {throw "Face detection default model failed with exit code $LASTEXITCODE."}
456+
457+
& $faceExe -i $inputImage -o $outputPrecise -m precise
458+
if ($LASTEXITCODE -ne 0) {throw "Face detection precise model failed with exit code $LASTEXITCODE."}
459+
Pop-Location
460+
461+
foreach ($output in @($outputFast, $outputPrecise)) {
462+
if (-not (Test-Path $output)) {throw "Expected output image was not created: $output"}
463+
464+
if ((Get-Item $output).Length -le 0) {throw "Output image is empty: $output"}
465+
}
466+
}
467+
finally {
468+
Pop-Location -ErrorAction SilentlyContinue
469+
Remove-Item -Recurse -Force $work -ErrorAction SilentlyContinue
470+
}
471+
```
472+
<!-- @test:end -->
473+
<!-- @os:end -->
474+
475+
<!-- @os:linux -->
476+
<!-- @test:id=cvml-build-and-face-detection-linux timeout=1800 hidden=True -->
477+
```bash
478+
set -euo pipefail
479+
480+
export OPENCV_INSTALL_ROOT="${OPENCV_INSTALL_ROOT:-/opt/opencv-4.11.0}"
481+
export OpenCV_DIR="${OpenCV_DIR:-/opt/opencv-4.11.0/lib/cmake/opencv4}"
482+
483+
playbook_root="$PWD"
484+
485+
if [ -z "${OPENCV_INSTALL_ROOT:-}" ]; then
486+
echo "OPENCV_INSTALL_ROOT is not set."
487+
exit 1
488+
fi
489+
490+
work="$PWD/cvml-test"
491+
mkdir -p "$work"
492+
cleanup() {
493+
rm -rf "$work"
494+
}
495+
trap cleanup EXIT
496+
497+
repo="$work/RyzenAI-SW"
498+
499+
git lfs install
500+
git clone --depth 1 https://github.com/amd/RyzenAI-SW.git "$repo"
501+
502+
cd "$repo"
503+
git lfs pull
504+
505+
cvml_root="$repo/Ryzen-AI-CVML-Library"
506+
if [ ! -d "$cvml_root" ]; then
507+
echo "Ryzen-AI-CVML-Library folder was not found after cloning RyzenAI-SW."
508+
exit 1
509+
fi
510+
511+
lfs_candidate="$(find "$cvml_root/linux" -type f \( -name "*.so" -o -name "*.amod" -o -name "*.xclbin" \) | head -n 1 || true)"
512+
if [ -z "$lfs_candidate" ]; then
513+
echo "No Linux CVML binary/runtime files were found. Git LFS may not have pulled the assets."
514+
exit 1
515+
fi
516+
517+
if head -n 1 "$lfs_candidate" | grep -q "version https://git-lfs.github.com/spec"; then
518+
echo "Git LFS file was downloaded as a pointer instead of the real binary: $lfs_candidate"
519+
exit 1
520+
fi
521+
522+
samples_dir="$cvml_root/samples"
523+
build_dir="$samples_dir/build"
524+
525+
cmake -S "$samples_dir" -B "$build_dir" -DOPENCV_INSTALL_ROOT="$OPENCV_INSTALL_ROOT"
526+
cmake --build "$build_dir" --config Release --parallel "$(nproc)"
527+
528+
face_exe="$build_dir/cvml-sample-face-detection/cvml-sample-face-detection"
529+
depth_exe="$build_dir/cvml-sample-depth-estimation/cvml-sample-depth-estimation"
530+
mesh_exe="$build_dir/cvml-sample-face-mesh/cvml-sample-face-mesh"
531+
532+
for exe in "$face_exe" "$depth_exe" "$mesh_exe"; do
533+
if [ ! -x "$exe" ]; then
534+
echo "Expected executable was not found or is not executable: $exe"
535+
exit 1
536+
fi
537+
done
538+
539+
export LD_LIBRARY_PATH="$cvml_root/linux:/opt/xilinx/xrt/lib:${LD_LIBRARY_PATH:-}"
540+
541+
for dir in "$OPENCV_INSTALL_ROOT/lib" "$OPENCV_INSTALL_ROOT/lib64" "$OPENCV_INSTALL_ROOT/build/lib"; do
542+
if [ -d "$dir" ]; then
543+
export LD_LIBRARY_PATH="$dir:$LD_LIBRARY_PATH"
544+
fi
545+
done
546+
547+
input_image="$playbook_root/sample_face.jpg"
548+
if [ ! -f "$input_image" ]; then
549+
input_image="$work/sample_face.jpg"
550+
curl -L -o "$input_image" "https://images.pexels.com/photos/895863/pexels-photo-895863.jpeg?cs=srgb&dl=pexels-jopwell-895863.jpg&fm=jpg"
551+
fi
552+
553+
output_fast="$work/output_face_fast.jpg"
554+
output_precise="$work/output_face_precise.jpg"
555+
556+
cd "$(dirname "$face_exe")"
557+
558+
"$face_exe" -i "$input_image" -o "$output_fast"
559+
"$face_exe" -i "$input_image" -o "$output_precise" -m precise
560+
561+
for output in "$output_fast" "$output_precise"; do
562+
if [ ! -s "$output" ]; then
563+
echo "Expected output image was not created or is empty: $output"
564+
exit 1
565+
fi
566+
done
567+
```
568+
<!-- @test:end -->
569+
<!-- @os:end -->
570+
299571
## Integrating CVML into Your Own Application
300572

301573
To use the CVML Library in your own C++ project, add it via CMake's `find_package`:

0 commit comments

Comments
 (0)