ROS和OpenCV4的DNN模块出现命名空间错误

使用ROS,OpenCV的dnn模块和CLion时遇到命名空间问题。这个问题似乎是DNN模块所独有的,因为其他ROS和OpenCV功能可以正常工作。虽然我的代码似乎可以编译和构建,但出现了lint错误:No member named readNetFromDarknet in namespace 'cv::dnn'。当我访问DNN模块中的任何内容时,都会发生该错误。

在我的头文件中定义:

cv::dnn::Net net;

产生错误No type named Net in namespace 'cv::dnn'

在我的班级文件中定义:

void HumanDetector::setupNetwork() {
    net = cv::dnn::readNetFromDarknet(MODEL_CONFIG,MODEL_WEIGHTS);
    net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
    net.setPreferabletarget(cv::dnn::DNN_TARGET_CPU);
}

产生类似的问题。

但是,在CLion中,我可以Ctrl +单击任何所谓的未定义成员或类型,然后查看它们的源代码。我怀疑这可能与我的CMakeLists配置或IDE设置有关。这是我的cmake文件:

cmake_minimum_required(VERSION 2.8.3)
project(followbot)

## Compile as C++11,supported in ROS Kinetic and newer
add_compile_options(-std=c++11)
set(CATKIN_ENABLE_TESTING OFF)
set(OpenCV_libraRY_DIR /usr/local/lib)
set(OpenCV_DIR "/usr/local/lib")

## Find catkin macros and libraries
find_package(OpenCV 4.1.2 REQUIRED PATHS /usr/local NO_DEFAULT_PATH)
find_package(catkin REQUIRED COMPONENTS
        roscpp
        geometry_msgs
        std_msgs
        message_generation
        teb_local_planner
)


add_message_files(
        FILES
        Point2.msg
)

generate_messages(
        DEPENDENCIES
)


###################################
## catkin specific configuration ##
###################################
## The catkin_package macro generates cmake config files for your package
## Declare things to be passed to dependent projects
## INCLUDE_DIRS: uncomment this if your package contains header files
## libraRIES: libraries you create in this project that dependent projects also need
## CATKIN_DEPENDS: catkin_packages dependent projects also need
## DEPENDS: system dependencies of this project that dependent projects also need
catkin_package(
        INCLUDE_DIRS include
        CATKIN_DEPENDS
            roscpp
            message_generation
            message_runtime
            std_msgs
            geometry_msgs
            teb_local_planner
        DEPENDS OpenCV
)


###########
## Build ##
###########

## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
        include
        ${catkin_INCLUDE_DIRS}
        ${OpenCV_INCLUDE_DIRS}
)

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_executable(${PROJECT_NAME} src/node.cpp src/cloud.cpp src/human.cpp)

## Link the executable to the OpenCV libraries
link_directories(${OpenCV_libraRY_DIR})
target_link_libraries(followbot ${OpenCV_libraRIES} ${catkin_libraRIES})
qayin123 回答:ROS和OpenCV4的DNN模块出现命名空间错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3041333.html

大家都在问