对‘cv::rectangle(cv::_InputOutputArray const&, cv::Rect_<int>, cv::Scalar_<double> const&, int, int,

对‘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;

}



 

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
非常抱歉,我之前的回答有一些错误。请使用以下修改后的代码: ```cpp #include <iostream> #include <opencv2/opencv.hpp> #include <opencv2/linemod.hpp> using namespace std; using namespace cv; void drawResponse(const std::vector<cv::linemod::Match>& matches, cv::Mat& dst, const std::vector<cv::Ptr<cv::linemod::Template>>& templates, const cv::Ptr<cv::linemod::Detector>& detector); int main() { // 读取模板图片 cv::Ptr<cv::linemod::Detector> detector = cv::linemod::getDefaultLINE(); std::vector<cv::Mat> templateImages; cv::Mat templateImage = cv::imread("template.png", 0); if (templateImage.empty()) { std::cout << "Failed to read template image!" << std::endl; return -1; } templateImages.push_back(templateImage); // 添加模板 std::string class_id = "template"; detector->addTemplate(templateImages, class_id); // 读取视频 cv::VideoCapture cap("video.mp4"); if (!cap.isOpened()) { std::cout << "Failed to open video!" << std::endl; return -1; } // 创建窗口 cv::namedWindow("Template Matching", cv::WINDOW_NORMAL); // 进行模板匹配 cv::Mat frame; while (cap.read(frame)) { // 转换为灰度图像 cv::Mat gray; cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY); // 运行模板匹配 std::vector<cv::linemod::Match> matches; detector->match(gray, 80, matches); // 绘制匹配结果 drawResponse(matches, frame, detector->getTemplates(class_id), detector); // 显示匹配结果 cv::imshow("Template Matching", frame); // 按下ESC键退出 if (cv::waitKey(1) == 27) break; } // 释放资源 cv::destroyAllWindows(); cap.release(); return 0; } void drawResponse(const std::vector<cv::linemod::Match>& matches, cv::Mat& dst, const std::vector<cv::Ptr<cv::linemod::Template>>& templates, const cv::Ptr<cv::linemod::Detector>& detector) { for (size_t i = 0; i < matches.size(); ++i) { const cv::linemod::Match& match = matches[i]; const std::vector<cv::linemod::Template>& classTemplates = templates[match.class_id]->getTemplates(); for (size_t j = 0; j < classTemplates.size(); ++j) { cv::Mat display = dst.clone(); cv::Rect rect = classTemplates[j].boundingRect; cv::rectangle(display, rect, cv::Scalar(0, 255, 255)); cv::Point center(match.x, match.y); cv::circle(display, center, 5, cv::Scalar(0, 0, 255), 2); cv::imshow("Template Matching", display); } } } ``` 请将示例代码中的`template.png`和`video.mp4`替换为你自己的模板图片和视频文件路径。这些修改应该能够解决之前提到的问题。如果还有其他问题,请随时提问!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值