opencv學習實踐(3) cv::waitKey()的使用

whisperrr發表於2021-08-21

  本文為測試cv::waitKey()的觸發條件

  1.程式準備

  mkdir -p opencv_test/src

  cv opencv_test/src

  catkin_create_pkg commandlineparse std_msgs rospy roscpp cv_bridge

  # meng @ meng in ~/my_learning/opencv_test [16:13:15]

  $ tree

  .

  └── src

  ├── CMakeLists.txt -> /opt/ros/kinetic/share/catkin/cmake/toplevel.cmake

  └── commandlineparse

  ├── CMakeLists.txt

  ├── include

  │ └── commandlineparse

  ├── package.xml

  └── src

  ├── commandlineparse_node.cpp

  └── tulip.jpg 大連無痛人流哪家好  

  5 directories, 5 files

  如上所述,新增檔案commandlineparse_node.cpp(上面倒數第三行),修改CMakeLists.txt(上面commandlineparse資料夾內的)

  commandlineparse_node.cpp,main函式內第二行為本地圖片的絕對路徑

  #include "opencv2/imgproc.hpp"

  #include "opencv2/highgui.hpp"

  #include "opencv2/core.hpp"

  #include "opencv2/imgcodecs.hpp"

  #include "iostream"

  #include "ros/ros.h"

  using namespace cv;

  using namespace std;

  int main(int argc,char** argv){

  Mat src;

  src=imread("/home/meng/my_learning/opencv/opencv_ws1/src/commandLineParse/src/tulip.jpg",1);

  namedWindow("my_window",WINDOW_NORMAL);

  imshow("my_window",src);

  waitKey(0);

  return 0;

  }

  CMakeLists.txt

  cmake_minimum_required(VERSION 3.0.2)

  project(commandlineparse)

  find_package(catkin REQUIRED COMPONENTS

  cv_bridge

  roscpp

  rospy

  std_msgs

  )

  find_package(OpenCV REQUIRED)

  catkin_package()

  include_directories(

  ${catkin_INCLUDE_DIRS} ${OpenCV_INCLUDE_DIRS} )

  add_executable(commandlineparse_node src/commandlineparse_node.cpp)

  target_link_libraries(commandlineparse_node

  ${catkin_LIBRARIES} ${OpenCV_LIBS} )


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70005147/viewspace-2788139/,如需轉載,請註明出處,否則將追究法律責任。

相關文章