对‘cv::rectangle(cv::_InputOutputArray const&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)’未定义的引用
cmake_minimum_required(VERSION 2.8.3)
project(drone_detect)
set(CMAKE_BUILD_TYPE "Release")
ADD_COMPILE_OPTIONS(-std=c++11 )
ADD_COMPILE_OPTIONS(-std=c++14 )
## By adding -Wall and -Werror, the compiler does not ignore warnings anymore,
## enforcing cleaner code.
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")
## Find catkin macros and libraries
find_package(catkin REQUIRED
COMPONENTS
roscpp
sensor_msgs
roslint
cv_bridge
message_filters
)
## Find system libraries
find_package(Eigen3 REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Boost REQUIRED)
###################################
## 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
## This is only necessary because Eigen3 sets a non-standard EIGEN3_INCLUDE_DIR variable
${EIGEN3_INCLUDE_DIR}
LIBRARIES
CATKIN_DEPENDS
roscpp
sensor_msgs
DEPENDS OpenCV Eigen Boost
## find_package(Eigen3) provides a non standard EIGEN3_INCLUDE_DIR instead of Eigen3_INCLUDE_DIRS.
## Therefore, the DEPEND does not work as expected and we need to add the directory to the INCLUDE_DIRS
# Eigen3
## Boost is not part of the DEPENDS since it is only used in source files,
## Dependees do not depend on Boost when they depend on this package.
)
###########
## Build ##
###########
## Specify additional locations of header files
## Your package locations should be listed before other locations
include_directories(
include
${catkin_INCLUDE_DIRS}
# Set manually because Eigen sets a non standard INCLUDE DIR
${EIGEN3_INCLUDE_DIR}
# Set because Boost is an internal dependency, not transitive.
${Boost_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
)
## Declare cpp executables
add_executable(${PROJECT_NAME}
src/${PROJECT_NAME}_node.cpp
src/drone_detector.cpp
)
target_compile_features(${PROJECT_NAME} INTERFACE cxx_std_11)
## Add dependencies to exported targets, like ROS msgs or srvs
add_dependencies(${PROJECT_NAME}
${catkin_EXPORTED_TARGETS}
)
target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${OpenCV_LIBS}
)
#############
## Install ##
#############
# Mark executables and/or libraries for installation
install(
TARGETS ${PROJECT_NAME}
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
# Mark cpp header files for installation
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
# Mark other files for installation
install(
DIRECTORY doc
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
#############
## Testing ##
#############
# if(${CATKIN_ENABLE_TESTING})
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
# ## Add gtest based cpp test target and link libraries
# catkin_add_gtest(${PROJECT_NAME}-test
# test/test_drone_detector.cpp)
# target_link_libraries(${PROJECT_NAME}-test)
# endif()
##########################
## Static code analysis ##
##########################
roslint_cpp()
cv::rectangle(depth_img_, cv::Rect(searchbox_lu_[i], searchbox_rd_[i]), cv::Scalar(0, 0, 0), 5, cv::LINE_8, 0);
cv::rectangle(depth_img_, cv::Rect(boundingbox_lu_[i], boundingbox_rd_[i]), cv::Scalar(0, 0, 0), 5, cv::LINE_8, 0);
/usr/bin/ld: warning: libopencv_imgcodecs.so.3.2, needed by /opt/ros/melodic/lib/libcv_bridge.so, may conflict with libopencv_imgcodecs.so.3.3
/usr/bin/ld: warning: libopencv_core.so.3.3, needed by /usr/local/lib/libopencv_imgcodecs.so.3.3.1, may conflict with libopencv_core.so.3.2
CMakeFiles/drone_detect.dir/src/drone_detector.cpp.o:在函数‘detect::DroneDetector::rcvDepthImgCallback(boost::shared_ptr<sensor_msgs::Image_<std::allocator<void> > const> const&)’中:
/home/amov/Prometheus/Modules/ego_planner/ego-planner-swarm/src/planner/drone_detect/src/drone_detector.cpp:202:对‘cv::rectangle(cv::_InputOutputArray const&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)’未定义的引用
/home/amov/Prometheus/Modules/ego_planner/ego-planner-swarm/src/planner/drone_detect/src/drone_detector.cpp:203:对‘cv::rectangle(cv::_InputOutputArray const&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int, int)’未定义的引用
collect2: error: ld returned 1 exit status
bool test_mode = 1;
int test_path = 0;
bool MBPlanner::setVelCb(planner_msgs::planner_set_vel::Request& req,
planner_msgs::planner_set_vel::Response& res) {
do_set_vel = req.set;
vel_to_set(0) = req.root_vel.linear.x;
vel_to_set(1) = req.root_vel.linear.y;
vel_to_set(2) = req.root_vel.linear.z;
res.success = true;
return true;
}
void yawToQuaternion(double yaw, geometry_msgs::Quaternion& quaternion) {
quaternion.w = cos(yaw / 2);
quaternion.x = 0;
quaternion.y = 0;
quaternion.z = sin(yaw / 2);
}
void updatePose(geometry_msgs::Pose& pose, double new_x, double new_y) {
double dx = new_x - pose.position.x;
double dy = new_y - pose.position.y;
double yaw = std::atan2(dy, dx);
pose.position.x = new_x;
pose.position.y = new_y;
pose.orientation = tf::createQuaternionMsgFromYaw(yaw);
}
bool MBPlanner::testmodeServiceCallback(planner_msgs::planner_srv::Request& req,
planner_msgs::planner_srv::Response& res) {
//改,测试模式
if (test_mode){
res.path.clear();
test_path ++;
if (test_path == 5 ){
test_mode = 0;
}
}
else{
res.path.clear();
cout<<"停"<<endl;
return 1;
}
// 初始化路径点
geometry_msgs::Pose current_pose;
current_pose.position.x =current_state_.position(0); // 初始位置
current_pose.position.y = current_state_.position(1);
current_pose.position.z = current_state_.position(2); // 高度固定为0.5
current_pose.orientation = tf::createQuaternionMsgFromYaw(current_state_.yaw); // 初始方向朝向x轴正方向
const double delta_theta = M_PI / 40.0; // 圆弧路径的角度增量
const double radius = 1.0; // 圆弧的半径
switch(test_path) {
case 1: {
// 直线路径
for (double x = 0.2; x <= 1.63; x += 0.143) {
updatePose(current_pose, x, 0);
res.path.push_back(current_pose);
}
break;
}
case 2: {
// 圆弧路径
for (double theta = 0; theta <= M_PI/2; theta += delta_theta) {
double x = 1.63 + radius * sin(theta);
double y = 1-radius * cos(theta);
updatePose(current_pose, x, y);
current_pose.position.z =current_pose.position.z - 0.008;
res.path.push_back(current_pose);
}
break;
}
case 3: {
// 垂直线路径
for (double y = current_pose.position.y; y <= 3.1; y += 0.23) {
updatePose(current_pose, 2.63, y);
current_pose.position.z =current_pose.position.z ;
res.path.push_back(current_pose);
}
break;
}
case 4: {
// 圆弧路径
for (double theta = M_PI/2; theta >= 0; theta -= delta_theta) {
double x = 1.63 + radius * sin(theta);
double y = 3.1 + radius * cos(theta);
updatePose(current_pose, x, y);
current_pose.position.z =current_pose.position.z + 0.008;
res.path.push_back(current_pose);
}
break;
}
case 5: {
// 反向直线路径
for (double x = 1.63; x >= -0.5; x -= 0.31) {
updatePose(current_pose, x, 4.0);
current_pose.position.z =current_pose.position.z + 0.03;
res.path.push_back(current_pose);
}
break;
}
}
return true;
}