重庆平台网站建设费用,网页设计作业源码,建设网站需要哪些,网站建设介绍会发言稿目录
准备
准备标定板
新建容器
新建usb_cam话题的ROS功能包
编写代码
编译
运行功能包
标定
安装camera_calibration标定功能包
启动发布usb_cam话题的功能包
启动camera_calibration标定功能包 准备
usb相机
标定板
一个带有ROS的docker镜像。
准备标定板
图…
目录
准备
准备标定板
新建容器
新建usb_cam话题的ROS功能包
编写代码
编译
运行功能包
标定
安装camera_calibration标定功能包
启动发布usb_cam话题的功能包
启动camera_calibration标定功能包 准备
usb相机
标定板
一个带有ROS的docker镜像。
准备标定板
图片链接
棋盘格图片
打印粘贴。或者可以使用手机平板等屏幕展示这张棋盘照片测量棋盘小格尺寸并保证标定过程中图片不被缩放。
新建容器
使用--privileged参数建立镜像。基础的代码
sudo docker run -it --privileged --namelab1 your_image_name /bin/bash
修改 your_image_name为你的docker镜像名。--privileged参数使容器与宿主机共用device设备有相同的/dev文件。但是在进入容器之前先连接相机再进入容器防止进入容器后刷新不出相机。
docker run的其他参数根据需要自行设置。
连接相机
进入容器
新建usb_cam话题的ROS功能包
新建ROS功能包用来发布usb_cam的话题。
编写代码
使用C语言编写示例如下
新建功能包而后写入核心代码
img_publisher.cpp文件 #include ros/ros.h
#include image_transport/image_transport.h
#include opencv2/highgui.hpp
#include opencv2/calib3d.hpp
#include cv_bridge/cv_bridge.h
#include iostreamint main(int argc, char** argv) {ros::init(argc, argv, img_publisher);ros::NodeHandle nh;image_transport::ImageTransport it(nh);image_transport::Publisher pub it.advertise(camera/image, 1);cv::VideoCapture cap;cv::Mat frame;int deviceID 0;if (argc 1)deviceID argv[1][0] - 0;int apiID cv::CAP_ANY;cap.open(deviceID apiID);if (!cap.isOpened()) {std::cerr ERROR! Unable to open camera std::endl;return -1;}ros::Rate loop_rate(30);while (nh.ok()) {cap.read(frame);if (!frame.empty()) {sensor_msgs::ImagePtr msg cv_bridge::CvImage(std_msgs::Header(), bgr8, frame).toImageMsg();pub.publish(msg);}ros::spinOnce();loop_rate.sleep();}return 0;
}
CMakeLists.txt文件
cmake_minimum_required(VERSION 3.0.2)
project(usb_cam)## Compile as C11, supported in ROS Kinetic and newer
# add_compile_options(-stdc11)## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTScv_bridgeimage_transportroscppsensor_msgsstd_msgs
)
find_package(OpenCV REQUIRED)
message(${OpenCV_VERSION})###################################
## 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
# LIBRARIES usb_cam
# CATKIN_DEPENDS cv_bridge image_transport roscpp sensor_msgs std_msgs
# DEPENDS system_lib
)###########
## 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}
)add_executable(img_publisher src/img_publisher.cpp)
add_executable(img_viewer src/img_viewer.cpp)target_link_libraries(img_publisher ${catkin_LIBRARIES} ${OpenCV_LIBS})
target_link_libraries(img_viewer ${catkin_LIBRARIES} ${OpenCV_LIBS})
编译
打开终端
catkin_make
在~/.bashrc加入环境变量。
打开终端
gedit ~/.bashrc
文末写入
source ~/catkin_ws/devel/setup.bash保存文件关闭。
运行功能包
打开终端
rosrun usb_cam img_publisher
会发布一个话题
查看话题
rostopic list正常接入相机功能包才正常运行此时会出现包括/camera/image话题等一系列话题。 标定
安装camera_calibration标定功能包
查看ROS的功能包
rospack list
查看是否有“camera_calibration”功能包没有则需要安装
rosdep install camera_calibration
启动发布usb_cam话题的功能包
打开终端
rosrun usb_cam img_publisher
查看话题
rostopic list正常接入相机功能包才正常运行此时会出现包括/camera/image话题等一系列话题。
启动camera_calibration标定功能包
打开终端
rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.20 image:/camera/image
其中 --size 8x6是棋盘交点的数量9*7的格子就会有8*6个交点
--square 0.20是一个小棋盘格大小单位米。
image:/camera/imageimage:相机话题名。
正常启动后弹出标定窗口间断地调整相机位置直到右侧calibrate按钮亮起 Moving the Checkerboard In order to get a good calibration you will need to move the checkerboard around in the camera frame such that: checkerboard on the cameras left, right, top and bottom of field of view X bar - left/right in field of view Y bar - top/bottom in field of view Size bar - toward/away and tilt from the camera checkerboard filling the whole field of view checkerboard tilted to the left, right, top and bottom (Skew) At each step, hold the checkerboard still until the image is highlighted in the calibration window. 移动棋盘 为了获得良好的校准您需要在相机框架中移动棋盘以便 相机视野左、右、上、下的棋盘 X条-视野中的左/右 Y条-视野中的顶部/底部 尺寸条-朝向/远离相机并倾斜 棋盘填充整个视野 向左、右、上、下倾斜的棋盘倾斜 在每一步中保持棋盘静止直到图像在校准窗口中高亮显示。 点击开始计算。计算结束后save按钮亮起结果点save按钮保存 If you are satisfied with the calibration, click COMMIT to send the calibration parameters to the camera for permanent storage. The GUI exits and you should see writing calibration data to ... in the console. 如果您对校准感到满意请单击COMMIT将校准参数发送到相机以进行永久存储。GUI退出您应该在控制台中看到“正在将校准数据写入…”。 参考 标定过程及参数 相机内参标定究竟标了什么相机内参外参保姆级教程 - 知乎 camera_calibration标定功能包介绍 camera_calibration/Tutorials/MonocularCalibration - ROS Wiki