Skip to content

[Enhancement] Require OpenCV >= 4 for cpp_api tests, remove legacy OpenCV 3 build support - #507

Open
levxn wants to merge 6 commits into
ROCm:developfrom
levxn:fix/support-opencv-v4+-only
Open

[Enhancement] Require OpenCV >= 4 for cpp_api tests, remove legacy OpenCV 3 build support#507
levxn wants to merge 6 commits into
ROCm:developfrom
levxn:fix/support-opencv-v4+-only

Conversation

@levxn

@levxn levxn commented Aug 11, 2026

Copy link
Copy Markdown
Member

Motivation

Fixes #433: Removes compiling option to build from older versions of OpenCV < 4

Technical Details

Updated all tests/cpp_api/*/CMakeLists.txt to require OpenCV_VERSION_MAJOR GREATER_EQUAL 4 instead of allowing EQUAL 3 OR EQUAL 4, and removed the USE_OPENCV_4 compile-time toggle. In the corresponding .cpp files, the old-API compatibility macros (CV_LOAD_IMAGE_COLOR, CV_BGR2GRAY, CV_RGB2BGR, CV_FONT_HERSHEY_SIMPLEX, CV_FILLED, CV_WINDOW_AUTOSIZE, cvDestroyWindow) are now defined unconditionally rather than gated behind #if USE_OPENCV_4, since there is no longer an OpenCV-3 code path to branch on. Also removed the legacy #include <opencv/highgui.h> fallback include that was only reachable in the OpenCV-3 branch.

Affected: basic_test, dataloader, dataloader_multithread, dataloader_tf, external_source, image_augmentation, multiple_dataloaders_test, performance_tests, performance_tests_with_depth, unit_tests, video_tests. serialization_test was already OpenCV-4-only and required no changes.

Test Plan

Configured and built each tests/cpp_api/* project individually against the system OpenCV (4.6.x) and confirmed the CMake version check now only accepts 4+, with no leftover OpenCV-3/USE_OPENCV_4 references:

for d in basic_test dataloader dataloader_tf dataloader_multithread external_source \
         multiple_dataloaders_test performance_tests performance_tests_with_depth \
         unit_tests video_tests image_augmentation serialization_test; do
  echo "=== $d ==="
  rm -rf "tests/cpp_api/$d/build_verify"
  cmake -S "tests/cpp_api/$d" -B "tests/cpp_api/$d/build_verify" 2>&1 | grep -i "opencv\|error"
  cmake --build "tests/cpp_api/$d/build_verify" -j"$(nproc)" 2>&1 | tail -n 20
done

# confirm no leftover OpenCV<4 gating/macros remain anywhere in the test tree
grep -rn "USE_OPENCV_4\|OpenCV_VERSION_MAJOR.*EQUAL 3\|CV_LOAD_IMAGE_COLOR\|CV_BGR2GRAY\|CV_RGB2BGR\|CV_FONT_HERSHEY_SIMPLEX\|CV_FILLED\|CV_WINDOW_AUTOSIZE\|cvDestroyWindow\|opencv/highgui.h" tests/cpp_api/

Test Result

All 11 updated cpp_api test projects configured and built cleanly against OpenCV 4.6.x, each reporting:

-- OpenCV Found -- Version-4.6.X Supported
[100%] Built target <test_name>

for: basic_test, dataloader, dataloader_tf, dataloader_multithread, external_source, multiple_dataloaders_test, performance_tests, performance_tests_with_depth, unit_tests, video_tests, image_augmentation.

Follow-up grep confirms the CMake OpenCV_VERSION_MAJOR check now only appears as GREATER_EQUAL 4 (including serialization_test, unchanged), with zero remaining hits for USE_OPENCV_4 or any OpenCV-3-only code path.

@sruthi0107 sruthi0107 self-assigned this Aug 11, 2026
@kiritigowda kiritigowda added enhancement New feature or request bug fix labels Aug 12, 2026
sruthi0107
sruthi0107 previously approved these changes Aug 14, 2026

@sruthi0107 sruthi0107 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenCV>=4, Build succeeds and all 21/21 ctests pass. With OpenCV 3.x, ctests degrade gracefully to a warning and 21/21 pass. Tested on gfx1100:

Running tests...
Test project /home/sruthi/rocAL/build-pr-507
      Start  1: basic_test_cpu
 1/21 Test  #1: basic_test_cpu .....................   Passed    2.30 sec
      Start  2: basic_test_gpu
 2/21 Test  #2: basic_test_gpu .....................   Passed    0.37 sec
      Start  3: basic_test_gray
 3/21 Test  #3: basic_test_gray ....................   Passed    0.31 sec
      Start  4: basic_test_rgb
 4/21 Test  #4: basic_test_rgb .....................   Passed    0.36 sec
      Start  5: dataloader_multithread_cpu
 5/21 Test  #5: dataloader_multithread_cpu .........   Passed    2.48 sec
      Start  6: dataloader_multithread_gpu
 6/21 Test  #6: dataloader_multithread_gpu .........   Passed    2.73 sec
      Start  7: performance_tests_cpu
 7/21 Test  #7: performance_tests_cpu ..............   Passed    1.51 sec
      Start  8: performance_tests_gpu
 8/21 Test  #8: performance_tests_gpu ..............   Passed    0.39 sec
      Start  9: performance_tests_with_depth_cpu
 9/21 Test  #9: performance_tests_with_depth_cpu ...   Passed    1.56 sec
      Start 10: performance_tests_with_depth_gpu
10/21 Test #10: performance_tests_with_depth_gpu ...   Passed    0.54 sec
      Start 11: unit_tests_cpu
11/21 Test #11: unit_tests_cpu .....................   Passed   13.02 sec
      Start 12: unit_tests_gpu
12/21 Test #12: unit_tests_gpu .....................   Passed    8.98 sec
      Start 13: unit_tests_gray
13/21 Test #13: unit_tests_gray ....................   Passed    3.73 sec
      Start 14: video_tests_ffmpeg
14/21 Test #14: video_tests_ffmpeg .................   Passed   48.37 sec
      Start 15: video_tests_rocdecode
15/21 Test #15: video_tests_rocdecode ..............   Passed   15.88 sec
      Start 16: basic_test_rocjpeg_gray
16/21 Test #16: basic_test_rocjpeg_gray ............   Passed    0.41 sec
      Start 17: basic_test_rocjpeg_rgb
17/21 Test #17: basic_test_rocjpeg_rgb .............   Passed    0.45 sec
      Start 18: serialization_test_cpu
18/21 Test #18: serialization_test_cpu .............   Passed    1.19 sec
      Start 19: serialization_test_gpu
19/21 Test #19: serialization_test_gpu .............   Passed    0.34 sec
      Start 20: checkpoint_save
20/21 Test #20: checkpoint_save ....................   Passed    1.99 sec
      Start 21: checkpoint_restore
21/21 Test #21: checkpoint_restore .................   Passed    2.24 sec

100% tests passed out of 21

Total Test time (real) = 109.18 sec```

Comment thread tests/cpp_api/basic_test/CMakeLists.txt
Comment thread tests/cpp_api/dataloader/CMakeLists.txt
Comment thread tests/cpp_api/external_source/external_source.cpp Outdated
Comment thread tests/cpp_api/image_augmentation/image_augmentation.cpp
@kiritigowda

Copy link
Copy Markdown
Collaborator

@levxn please address the review comments


list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake)

find_package(OpenCV QUIET)

@levxn levxn Aug 20, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed from other CI that

-- WARNING: OpenCV Not Found -- No Display Support

So OpenCV_FOUND is false and OpenCV_VERSION_MAJOR was never set

Comment thread tests/cpp_api/basic_test/CMakeLists.txt Outdated
message("-- WARNING: OpenCV Found -- Version-${OpenCV_VERSION_MAJOR}.${OpenCV_VERSION_MINOR}.X Not Supported")
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_OPENCV=0)
endif()
if(OpenCV_FOUND AND ${OpenCV_VERSION_MAJOR} GREATER_EQUAL 4)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when it reaches here, due to this it throws error

CMake Error at CMakeLists.txt:59 (if):
  if given arguments:

    "OpenCV_FOUND" "AND" "GREATER_EQUAL" "4"

  Unknown arguments specified

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LakshmiKumar23 shall I revert it back to how it was earlier?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, turns out CMake doesn't take the false as a short circuit like C++. Let's revert

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement] Remove compiling option to build from older versions of OpenCV < 4

4 participants