Skip to content

Latest commit

 

History

History
191 lines (157 loc) · 6.79 KB

File metadata and controls

191 lines (157 loc) · 6.79 KB

OpenCV DNN DictValue Fix Plan

Problem Statement

The BrightSign OpenCV 4.5.5 build is missing the cv2.dnn.DictValue class, causing failures when testing YOLOX and other deep learning functionality:

# python3 /storage/sd/python-init/test_cv2_dnn.py
Testing cv2.dnn module availability...
❌ Attribute error: module 'cv2.dnn' has no attribute 'DictValue'

Deep Analysis of the Problem

What is DictValue?

  • cv2.dnn.DictValue is a utility class in OpenCV's DNN module used for handling parameter dictionaries
  • It's part of the core DNN API and should be available when DNN module is properly compiled
  • The class is used internally by various DNN functions and is expected by opencv-python compatibility

Current Build Configuration Analysis

  • OpenCV recipe (bsoe-recipes/meta-bs/recipes-open/opencv/opencv_4.5.5.bb) has:
    • DNN enabled in PACKAGECONFIG (line 108)
    • Proper DNN build flags: -DBUILD_opencv_dnn=ON -DPROTOBUF_UPDATE_FILES=ON -DBUILD_PROTOBUF=OFF
    • Dependencies: protobuf, protobuf-native, python3-protobuf
    • opencv_contrib modules included
  • BrightSign SDK includes both opencv and python3-opencv packages
  • Protobuf recipe exists and looks properly configured

Likely Root Causes

  1. Python Binding Generation Failure

    • Cross-compilation issues preventing proper Python wrapper generation for DictValue
    • Missing or incomplete binding code generation during build
  2. Partial DNN Module Compilation

    • DNN module compiles but missing certain components/classes
    • Build warnings/errors during DNN compilation that don't fail the overall build
  3. Protobuf Version Compatibility

    • OpenCV 4.5.5 expecting different protobuf version than 3.20.3
    • Protobuf not properly linked during DNN module compilation
  4. Contrib Module Integration Issues

    • DictValue might be in contrib modules that aren't properly integrated
    • Missing opencv_contrib components during build
  5. Cross-Compilation Artifacts

    • ARM64 target compilation missing x86_64 build dependencies
    • Missing build-time protobuf components needed for binding generation

Investigation Plan

Phase 1: Build Diagnostics (Immediate)

  1. Extract and Examine Current SDK

    ./build --extract-sdk
    ./brightsign-x*.sh -d ./sdk -y
    • Inspect OpenCV Python bindings in sdk/
    • Check if libopencv_dnn exists and is properly linked
    • Verify protobuf libraries are present
  2. Test Individual OpenCV Build

    ./build --clean opencv
    ./build opencv 2>&1 | tee opencv_build.log
    • Look for DNN compilation warnings/errors
    • Check if Python binding generation logs show DictValue issues
  3. Examine Build Logs

    • Use docker exec to access build container logs
    • Check /home/builder/bsoe/brightsign-oe/build/tmp-glibc/work/*/temp/log.* for opencv build
    • Look for protobuf-related errors or DNN compilation issues

Phase 2: Source Code Analysis

  1. Check OpenCV Source

    • Examine /home/scott/workspace/Brightsign/brightsign-npu-yolo-extension/brightsign-oe for DictValue references
    • Verify DictValue exists in the OpenCV 4.5.5 source code
    • Check if contrib modules are properly included
  2. Python Binding Investigation

    • Look for cv2.cpp or similar binding files in build output
    • Check if DictValue binding code is generated
    • Compare with reference OpenCV builds

Phase 3: Dependency Verification

  1. Protobuf Integration Test

    ./build python3-protobuf
    • Ensure protobuf builds cleanly
    • Verify protobuf-native is available for build-time usage
  2. Check CMake Configuration

    • Examine CMakeCache.txt in opencv build directory
    • Verify PROTOBUF_FOUND and related variables
    • Check if DNN module is actually enabled in cmake

Phase 4: Targeted Fixes

Option A: OpenCV Recipe Enhancement

  1. Add Explicit DNN Verification

    # Add to opencv recipe
    EXTRA_OECMAKE += "-DBUILD_opencv_dnn=ON \
                      -DOPENCV_DNN_OPENCL=OFF \
                      -DWITH_PROTOBUF=ON \
                      -DPROTOBUF_UPDATE_FILES=ON"
  2. Enhance Python Binding Generation

    # Ensure Python bindings include all DNN components
    PACKAGECONFIG[python3] = "-DPYTHON3_NUMPY_INCLUDE_DIRS:PATH=${STAGING_LIBDIR}/${PYTHON_DIR}/site-packages/numpy/core/include \
                              -DBUILD_opencv_python3=ON \
                              -DPYTHON3_INCLUDE_DIR=${STAGING_INCDIR}/python3.8 \
                              -DPYTHON3_LIBRARY=${STAGING_LIBDIR}/libpython3.8.so,,python3-numpy,"

Option B: Protobuf Version Fix

  1. Update Protobuf Version
    • Check if OpenCV 4.5.5 needs newer protobuf
    • Update python3-protobuf recipe if needed

Option C: Custom Patch

  1. Create OpenCV DNN Patch
    • If DictValue binding is missing from source, create patch to add it
    • Add to opencv/files/ directory

Option D: Build Process Fix

  1. Add Build-time Verification
    do_compile:append() {
        # Verify DNN module compiled properly
        if [ ! -f ${WORKDIR}/build/lib/libopencv_dnn.so ]; then
            bbfatal "OpenCV DNN module failed to compile"
        fi
    }
    
    do_install:append() {
        # Verify Python bindings include DictValue
        ${STAGING_BINDIR_NATIVE}/python3 -c "import cv2.dnn; cv2.dnn.DictValue()" || bbfatal "DictValue not found in Python bindings"
    }

Phase 5: Testing and Validation

  1. Build Test Sequence

    ./build --clean opencv
    ./build opencv
    ./build --extract-sdk
    ./brightsign-x*.sh -d ./sdk -y
  2. SDK Verification

    • Test DictValue availability in extracted SDK
    • Run comprehensive cv2.dnn tests
    • Verify YOLOX compatibility
  3. Player Testing

    • Deploy to BrightSign player
    • Run test_cv2_dnn.py
    • Validate full YOLOX pipeline

Expected Outcomes

  • cv2.dnn.DictValue available in Python bindings
  • Full cv2.dnn module functionality restored
  • YOLOX and other DNN frameworks working properly
  • Clean build with no DNN-related warnings/errors

Rollback Plan

If fixes cause build failures:

  1. Revert to original opencv recipe
  2. Try alternative approaches (different protobuf version, minimal patches)
  3. Consider building DictValue as separate component if absolutely necessary

Time Estimates

  • Phase 1 (Diagnostics): 2-3 hours
  • Phase 2 (Analysis): 1-2 hours
  • Phase 3 (Dependencies): 1 hour
  • Phase 4 (Implementation): 2-4 hours (depending on fix complexity)
  • Phase 5 (Testing): 2-3 hours
  • Total: 8-13 hours

Success Criteria

  1. python3 -c "import cv2.dnn; print(cv2.dnn.DictValue())" works in SDK
  2. ✅ test_cv2_dnn.py passes all tests on BrightSign player
  3. ✅ YOLOX pipeline functional end-to-end
  4. ✅ Clean build logs with no DNN-related errors
  5. ✅ All existing OpenCV functionality still working