纲要
摄像头驱动
图像属性
图像压缩
### Realsense摄像头
点云展示
### 点云图像属性
## 摄像头标定
摄像头标定流程
如何使用标定文件
OpenCV
ROS与OpenCV的集成框架
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/b0ff143b710543839325d19c7a3c04c5.png
ROS+OpenCV 图像绘制(cpp)
#include <ros/ros.h>
#include <image_transport/image_transport.h>
#include <sensor_msgs/image_encodings.h>
#include <cv_bridge/cv_bridge.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>static const std::string OPENCV_WINDOW = "image_window";class ImageConverter{ros::NodeHandle nh;image_transport::ImageTransport it;image_transport::Subscriber image_sub;image_transport::Publisher image_pub;public:ImageConverter():it(nh){//订阅图像输入流 、发布图像输出流(话题名称,处理队列的大小为1,回调函数的名称,回调函数所处的类)image_sub = it.subscribe("/usb_cam/image_raw",1,&ImageConverter::imageCb,this);image_pub = it.advertise("cv_bridge_image",1);cv::namedWindow(OPENCV_WINDOW);}~ImageConverter(){cv::destroyWindow(OPENCV_WINDOW);}void imageCb(const sensor_msgs::ImageConstPtr& msg){//msg为图像信息在ROS中的地址cv_bridge::CvImagePtr cv_ptr;try{//创建一个图像数据的拷贝//toCvCopy复制数据并返回复制数据地址指针cv_bridge::CvImagePtr//将ROS图像消息转换为了CvImage以在OpenCV中使用//sensor_msgs::image_encodings::BGR8是”bgr8”字符串常量。cv_ptr = cv_bridge::toCvCopy(msg,sensor_msgs::image_encodings::BGR8);}catch (cv_bridge::Exception& e){ROS_ERROR("cv_bridge exception: %s",e.what());return;}//在opencv窗口画红圈if(cv_ptr->image.rows > 60 && cv_ptr->image.cols > 60)cv::circle(cv_ptr->image,cv::Point(50,50) , 10 , CV_RGB(255,0,0));//生成opencv窗口cv::imshow(OPENCV_WINDOW,cv_ptr->image);cv::waitKey(3);//将opencv生成的话题信息,转换为Image图像信息,通过iamge_pub发布出去,可以通过rqt_image_view订阅话题,查看opencv生成的红圈image_pub.publish(cv_ptr->toImageMsg()); }
};int main(int argc,char ** argv){ros::init(argc,argv,"image_converter");ImageConverter ic;ros::spin();return 0;}
ROS+OpenCV 图像绘制(python)
#!/usr/bin/env python
# -*- coding: utf-8 -*-import rospy
import cv2
from cv_bridge import CvBridge, CvBridgeError
from sensor_msgs.msg import Imageclass image_converter:def __init__(self): # 创建cv_bridge,声明图像的发布者和订阅者self.image_pub = rospy.Publisher("cv_bridge_image", Image, queue_size=1)self.bridge = CvBridge()self.image_sub = rospy.Subscriber("/usb_cam/image_raw", Image, self.callback)def callback(self,data):# 使用cv_bridge将ROS的图像数据转换成OpenCV的图像格式try:cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")except CvBridgeError as e:print e# 在opencv的显示窗口中绘制一个圆,作为标记(rows,cols,channels) = cv_image.shapeif cols > 60 and rows > 60 :cv2.circle(cv_image, (60, 60), 30, (0,0,255), -1)# 显示Opencv格式的图像cv2.imshow("Image window", cv_image)cv2.waitKey(3)# 再将opencv格式额数据转换成ros image格式的数据发布try:self.image_pub.publish(self.bridge.cv2_to_imgmsg(cv_image, "bgr8"))except CvBridgeError as e:print eif __name__ == '__main__':try:# 初始化ros节点rospy.init_node("cv_bridge_test")rospy.loginfo("Starting cv_bridge_test node")image_converter()rospy.spin()except KeyboardInterrupt:print "Shutting down cv_bridge_test node."cv2.destroyAllWindows()
ROS+OpenCV物体识别
源码
get2DLocation():获取桌面以及桌面物体的坐标
设置红色、绿色通道,通过像素点灰度值判断出黑色桌子的具体位置,将黑色像素点具体位置的二进制数值设置为255,非黑设置为0,计算出桌子中心点,最后将非0点画上方框
找红点、画蓝框
识别绿色圆柱(contours:轮廓)
分析