首页 > 系统相关 >ubuntu 使用自己的双目相机发布 ROS

ubuntu 使用自己的双目相机发布 ROS

时间:2024-07-01 18:09:08浏览次数:1  
标签:usb image 相机 camera cam ubuntu ROS cv left

https://blog.csdn.net/KID_yuan/article/details/101272384

https://blog.csdn.net/weixin_53073284/article/details/125671358

ls /dev/video*    //插上摄像头后打开终端查看是否检测到摄像头
mkdir -p  camera_ws/src                                       //新建工作空间
cd camera_ws/src/
git clone https://github.com/bosch-ros-pkg/usb_cam.git        //克隆功能包
cd ..
catkin_make                                                   //编译

报错:

CMake Error at /opt/ros/melodic/share/catkin/cmake/catkin_workspace.cmake:100 (message):
This workspace contains non-catkin packages in it, and catkin cannot build
a non-homogeneous workspace without isolation. Try the
'catkin_make_isolated' command instead.
Call Stack (most recent call first):
CMakeLists.txt:69 (catkin_workspace)

解决:

https://github.com/MIT-SPARK/Kimera-VIO-ROS/issues/13#issuecomment-883298337

重新使用: catkin build 构建

vim src/usb_cam/launch/usb_cam-test.launch
<launch>
  <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video0" />
    <param name="image_width" value="2560" />
    <param name="image_height" value="720" />
    <param name="pixel_format" value="yuyv" />
    <param name="camera_frame_id" value="usb_cam" />
    <param name="io_method" value="mmap"/>
  </node>
  <node name="image_view" pkg="image_view" type="image_view" respawn="false" output="screen">
    <remap from="image" to="/usb_cam/image_raw"/>
    <param name="autosize" value="true" />
  </node>
</launch>
cd ~/camera_ws
source devel/setup.bash
roslaunch usb_cam usb_cam-test.launch

报错:

ERROR: cannot launch node of type [usb_cam/usb_cam_node]: Cannot locate node of type [usb_cam_node] in package [usb_cam]. Make sure file exists in package path and permission is set to executable (chmod +x)

问题: 这好像是 冲突了。https://github.com/ros-drivers/usb_cam/issues/96#issuecomment-1400883250


分割线


注意!注意!注意!我们抛弃了上述方法。

rm -r  ~/camera_ws

参考:https://blog.csdn.net/chencaw/article/details/101193038

apt-get install ros-melodic-usb-cam
apt-get install ros-melodic-image-*
apt-get install ros-melodic-rqt-image-view
roscd usb_cam # 进入 `/opt/ros/melodic/share/usb_cam`
vim launch/usb_cam-test.launch

修改分辨率为 2560 720:

<param name="image_width" value="2560" />
<param name="image_height" value="720" />

运行:

roslaunch usb_cam usb_cam-test.launch

即可看到双目视频。


但是我们可视化出来是 双目图像在一个 图像中,我们需要分割双目图像。参考:

https://blog.csdn.net/weixin_48592526/article/details/122724361
https://www.guyuehome.com/34995

cd 
mkdir -p dcamera_ws/src 
cd dcamera_ws 
catkin_make
cd src
catkin_create_pkg camera_split cv_bridge image_transport roscpp sensor_msgs std_msgs camera_info_manager
vim src/camera_split/CMakeLists.txt

## 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(camera_split_node src/camera_split.cpp )
#指定链接库
target_link_libraries(camera_split_node
    ${catkin_LIBRARIES}
    ${OpenCV_LIBRARIES}
)
vim src/camera_split/launch/camera_split_no_calibration.launch

<launch>
    <node pkg="camera_split" type="camera_split_node" name="camera_split_node" output="screen" />
    <node pkg="image_view" type="image_view" name="image_view_left" respawn="false" output="screen">
        <remap from="image" to="/left_cam/image_raw"/>
        <param name="autosize" value="true" />
    </node>
    <node pkg="image_view" type="image_view" name="image_view_right" respawn="false" output="screen">
        <remap from="image" to="/right_cam/image_raw"/>
        <param name="autosize" value="true" />
    </node>
</launch>
vim src/camera_split/src/camera_split.cpp

#include <ros/ros.h>
#include <iostream>
#include <image_transport/image_transport.h>
#include <cv_bridge/cv_bridge.h>
#include <sensor_msgs/image_encodings.h>
#include <camera_info_manager/camera_info_manager.h>

#include <opencv2/opencv.hpp>
//#include <opencv2/imgproc/imgproc.hpp>
//#include <opencv2/highgui/highgui.hpp>

using namespace std;

class CameraSplitter
{
public:
    CameraSplitter():nh_("~"),it_(nh_)
    {
        image_sub_ = it_.subscribe("/usb_cam/image_raw", 1, &CameraSplitter::imageCallback, this);
        image_pub_left_ = it_.advertiseCamera("/left_cam/image_raw", 1);
        image_pub_right_ = it_.advertiseCamera("/right_cam/image_raw", 1);
        cinfo_ =boost::shared_ptr<camera_info_manager::CameraInfoManager>(new camera_info_manager::CameraInfoManager(nh_));

        //读取参数服务器参数,得到左右相机参数文件的位置
        string left_cal_file = nh_.param<std::string>("left_cam_file", "");
        string right_cal_file = nh_.param<std::string>("right_cam_file", "");
        if(!left_cal_file.empty())
        {
            if(cinfo_->validateURL(left_cal_file)) {
                cout<<"Load left camera info file: "<<left_cal_file<<endl;
                cinfo_->loadCameraInfo(left_cal_file);
                ci_left_ = sensor_msgs::CameraInfoPtr(new sensor_msgs::CameraInfo(cinfo_->getCameraInfo()));
            }
            else {
                cout<<"Can't load left camera info file: "<<left_cal_file<<endl;
                ros::shutdown();
            }
        }
        else {
            cout<<"Did not specify left camera info file." <<endl;
            ci_left_=sensor_msgs::CameraInfoPtr(new sensor_msgs::CameraInfo());
        }
        if(!right_cal_file.empty())
        {
            if(cinfo_->validateURL(right_cal_file)) {
                cout<<"Load right camera info file: "<<right_cal_file<<endl;
                cinfo_->loadCameraInfo(right_cal_file);
                ci_right_ = sensor_msgs::CameraInfoPtr(new sensor_msgs::CameraInfo(cinfo_->getCameraInfo()));
            }
            else {
                cout<<"Can't load right camera info file: "<<left_cal_file<<endl;
                ros::shutdown();
            }
        }
        else {
            cout<<"Did not specify right camera info file." <<endl;
            ci_right_=sensor_msgs::CameraInfoPtr(new sensor_msgs::CameraInfo());
        }
    }

    void imageCallback(const sensor_msgs::ImageConstPtr& msg)
    {
        cv_bridge::CvImageConstPtr cv_ptr;
        namespace enc= sensor_msgs::image_encodings;
        cv_ptr= cv_bridge::toCvShare(msg, enc::BGR8);
        //截取ROI(Region Of Interest),即左右图像,会将原图像数据拷贝出来。
        leftImgROI_=cv_ptr->image(cv::Rect(0,0,cv_ptr->image.cols/2, cv_ptr->image.rows));
        rightImgROI_=cv_ptr->image(cv::Rect(cv_ptr->image.cols/2,0, cv_ptr->image.cols/2, cv_ptr->image.rows ));
        //创建两个CvImage, 用于存放原始图像的左右部分。CvImage创建时是对Mat进行引用的,不会进行数据拷贝
        leftImgPtr_=cv_bridge::CvImagePtr(new cv_bridge::CvImage(cv_ptr->header, cv_ptr->encoding,leftImgROI_) );
        rightImgPtr_=cv_bridge::CvImagePtr(new cv_bridge::CvImage(cv_ptr->header, cv_ptr->encoding,rightImgROI_) );

        //发布到/left_cam/image_raw和/right_cam/image_raw
        ci_left_->header = cv_ptr->header; 	//很重要,不然会提示不同步导致无法去畸变
        ci_right_->header = cv_ptr->header;
        sensor_msgs::ImagePtr leftPtr =leftImgPtr_->toImageMsg();
        sensor_msgs::ImagePtr rightPtr =rightImgPtr_->toImageMsg();
        leftPtr->header=msg->header; 		//很重要,不然输出的图象没有时间戳
        rightPtr->header=msg->header;
        image_pub_left_.publish(leftPtr,ci_left_);
        image_pub_right_.publish(rightPtr,ci_right_);
    }

private:
    ros::NodeHandle nh_;
    image_transport::ImageTransport it_;
    image_transport::Subscriber image_sub_;
    image_transport::CameraPublisher image_pub_left_;
    image_transport::CameraPublisher image_pub_right_;
    boost::shared_ptr<camera_info_manager::CameraInfoManager> cinfo_;
    sensor_msgs::CameraInfoPtr ci_left_;
    sensor_msgs::CameraInfoPtr ci_right_;

    cv::Mat leftImgROI_;
    cv::Mat rightImgROI_;
    cv_bridge::CvImagePtr leftImgPtr_=NULL;
    cv_bridge::CvImagePtr rightImgPtr_=NULL;
};

int main(int argc,char** argv)
{
    ros::init(argc,argv, "camera_split");
    CameraSplitter cameraSplitter;
    ros::spin();
    return 0;
}
cd dcamera_ws
catkin_make
source ./devel/setup.bash
roslaunch camera_split camera_split_no_calibration.launch

请注意:这里我们不会出来画面。我们还需要另外启动一个终端。

cd /opt/ros/melodic/share/usb_cam
roslaunch usb_cam usb_cam-test.launch

然后就可以出来 3个 图像窗口了。分别是双目-左目-右目。

标签:usb,image,相机,camera,cam,ubuntu,ROS,cv,left
From: https://www.cnblogs.com/odesey/p/18278579

相关文章

  • ubuntu制作本地镜像(类似yum本地)
     1.原文件备份root@11g:/mnt#cd/etc/apt/root@11g:/etc/apt#cpsources.listbak_sources.list 2.挂载安装盘镜像mkdir-p/media/cdrom/root@11g:/soft/ios#cd/soft/iosroot@11g:/soft/ios#mountubuntu-18.04.6-desktop-amd64.iso-oloop/media/cdrommount:/media......
  • ros microros 使用超声波雷达测量距离
    我们使用的超声波模块一共有四个引脚,分别是TRIG即发送引脚,用于发送超声波ECHO即接收引脚,用于接收反射回来的超声波VCC电源接5VGND电源地一、新建工程新建example18_sr04二、编写代码带注释的代码如下#include<Arduino.h>#defineTrig27//设定SR04连接的Arduino引脚......
  • ubuntu与windows双系统时间不同步
    两个系统时间不同步是因为对于硬件时间(BIOS里的时间)的时区认定不一致,windows认为BIOS的时间是当前系统时区(中国时区:UTC+08(CST-8)),ubuntu认为BISO时间是UTC时区时间.两个系统在启动是按照BISO时间设置系统时间导致了系统时间差异。处理思路无非,修改windows或者ubuntu系统对于BIS......
  • ros mocroros 使用双核运行microros
    在硬件篇开始的第一节时,曾提到,我们所使用的开发板单片机是双核240M主频的,但是在后面的开发中我们并没有真正的使用了双核,主频也是使用的默认160MHZ。所以本节带你一起带你一起提升主频并启动双核进行MicoROS的双核。一、双核与RTOS介绍 所谓双核指的是ESP32单片机有两个内核,所......
  • Microsoft.AspNetCore.Builder.ForwardedHeadersOptions
    答案为ai生成ForwardedHeadersOptions是ASP.NETCore中用于配置转发头部的一个类。当应用程序位于负载均衡器(https://blog.csdn.net/cyl101816/article/details/135195729)、反向代理服务器等后面时,由于HTTP请求会通过多个代理或转发,原始的请求头(如X-Forwarded-For和X-For......
  • Ubuntu23.10 多个硬盘挂载到同一目录
    借鉴https://blog.csdn.net/qq_37054954/article/details/136262332https://www.zhihu.com/question/607744366/answer/3083634568系统:Ubuntu23.10版本:x86_64 无法识别df命令sudoaptinstallcoreutils场景:将/dev/sdb1/dev/sdc1/dev/sdd1/dev/sde1/dev/sdf1 5个硬......
  • Ubuntu23.10 安装SVN
    一、搭建环境查看Ubuntu系统的版本信息:可用cat/proc/version命令、uname-a命令与sb_release-a命令。Ubuntu:23.10 64位SVN:通过apt-get安装二:搭建步骤1.安装SVNsudoapt-getinstallsubversion安装成功后可以验证一下,通过如下命令:svnhelp      //--svn......
  • ubuntu配置网络信息
    环境:Os:18.04.1 1.备份配置文件root@11g:~#cd/etc/netplanroot@11g:/etc/netplan#root@11g:/etc/netplan#cp01-network-manager-all.yamlbak_01-network-manager-all.yaml 2.配置静态ip#LetNetworkManagermanagealldevicesonthissystemnetwork:ethernet......
  • c++使用matplotlibcpp,subplot() 报错问题-ubuntu22.04
    使用matplotlibcpp.h在C++代码中绘制图形plt::subplot();程序抛出运行时错误,terminatecalledafterthrowinganinstanceof'std::runtime_error'what():Calltosubplot()failed.解决方法:在matplotlibcpp.h文件中把PyTuple_SetItem(args,0,PyFloat_FromDouble(......
  • ros micro-ros 无线通信(wifi)
    在前面的学习中,我们一直通过串口通信来连接MicroROS,但一直扯着跟线是不是觉得很麻烦,本节我们利用开发板上的WIFI功能尝试使用无线的方式连接Agent。一、新建工程并添加依赖1.1新建工程1.2添加依赖&修改配置修改platformio.ini[env:featheresp32]platform=espressif32boa......