From bf890ca7b038193bae91be715673d2b518213ca2 Mon Sep 17 00:00:00 2001 From: Kiriti Gowda Date: Mon, 28 Mar 2022 16:42:43 -0700 Subject: [PATCH] Model Compiler - OpenCV 4 Support (#796) (#798) * Model Compiler - OpenCV 4 Support * OpenCV 4 - Updates --- model_compiler/python/nnir_to_openvx.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/model_compiler/python/nnir_to_openvx.py b/model_compiler/python/nnir_to_openvx.py index b6bdc3b607..6cbc55ea65 100644 --- a/model_compiler/python/nnir_to_openvx.py +++ b/model_compiler/python/nnir_to_openvx.py @@ -161,9 +161,19 @@ def generateCMakeFiles(graph,outputFolder): add_executable(anntest anntest.cpp) if(OpenCV_FOUND) - target_compile_definitions(anntest PUBLIC ENABLE_OPENCV=1) - include_directories(${OpenCV_INCLUDE_DIRS}) - target_link_libraries(anntest ${OpenCV_LIBRARIES}) + if(${OpenCV_VERSION_MAJOR} EQUAL 3 OR ${OpenCV_VERSION_MAJOR} EQUAL 4) + target_compile_definitions(anntest PUBLIC ENABLE_OPENCV=1) + include_directories(${OpenCV_INCLUDE_DIRS}) + target_link_libraries(anntest ${OpenCV_LIBRARIES}) + if(${OpenCV_VERSION_MAJOR} EQUAL 4) + target_compile_definitions(anntest PUBLIC USE_OPENCV_4=1) + else() + target_compile_definitions(anntest PUBLIC USE_OPENCV_4=0) + endif() + else() + target_compile_definitions(anntest PUBLIC ENABLE_OPENCV=0) + message("-- NOTE: anntest -- OpenCV Version-${OpenCV_VERSION_MAJOR}.${OpenCV_VERSION_MINOR}.X Not Supported") + endif() else(OpenCV_FOUND) target_compile_definitions(anntest PUBLIC ENABLE_OPENCV=0) endif(OpenCV_FOUND) @@ -1980,6 +1990,9 @@ def generateTestCPP(graph,argmaxOutput,fileName,virtual_tensor_flag): #include #include using namespace cv; +#if USE_OPENCV_4 +#define CV_LOAD_IMAGE_COLOR IMREAD_COLOR +#endif #endif #define ERROR_CHECK_OBJECT(obj) { vx_status status = vxGetStatus((vx_reference)(obj)); if(status != VX_SUCCESS) { vxAddLogEntry((vx_reference)context, status , "ERROR: failed with status = (%d) at " __FILE__ "#%d\\n", status, __LINE__); return status; } }