演示

一、工具
ROS+opencv
ubuntu18.04
二、原理
基于opencv的颜色识别,捕捉特定物品的hsv值来进行轮廓框取,最后包装与ROS框架中。
- 颜色识别
 - 鼠标事件响应
 - 保存hsv
 
按照我上一个博客完成了颜色识别,然后通过鼠标捕捉目标像素点的hsv值进行识别,最后将hsv保存再output.txt中
            
            
              cpp
              
              
            
          
          ofstream file("output.txt");
        if (file.is_open()) {
            file << "H: "<<H<<" S: " << S<< "  V: "<<V<< endl;
            ROS_INFO("成功保存参数");
            file.close();
        } else {
            ROS_ERROR("Failed to open file");
        }
        三、安装
            
            
              bash
              
              
            
          
          cd ~/catkin_ws/src
git clone https://github.com/jiezz12/color_detect.git
cd ..
catkin_make
        编译完成后进入launch文件夹修改一些参数
            
            
              XML
              
              
            
          
          <?xml version="1.0"?>
<launch>
  <node pkg="color_detect" name="opencv_camera" type="color_detect" output="screen"/>
            <param name="image_view" type="bool" value="true"/>
            <param name="video_device" type="int" value="0"/>
            <param name="width" type="int" value="640"/>
            <param name="height" type="int" value="480"/>
            <param name="H" type="int" value="100"/>
            <param name="S" type="int" value="100"/>
            <param name="V" type="int" value="100"/>
</launch>
        
- 图像可视化
 - 相机接口
 - 图像分辨率
 - 识别物品的hsv值
 
用法
            
            
              cpp
              
              
            
          
          roslaunch color_detect color_detec.launch
        会打开video窗口
通过点击窗口会保存新的hsv值

默认保存在/.ros/中,可以更改
话题查看
            
            
              XML
              
              
            
          
          rostopic echo /opencv_camera/color_detect
        发布方式为如果图像中没有识别物则会重复发布上次的坐标。

https://github.com/jiezz12/color_detect.git
https://github.com/jiezz12/color_detect.git