连接到ROS

时间:2016-10-12 17:04:24

标签: python opencv camera ros ar.drone

我遇到一个问题,当使用ardrone_autonomy ardrone.launch通过ROS连接无人机时,我无法连接到AR Drone 2相机。

我认为问题是由于我试图通过使用OpenCV和Python通过IP地址访问无人机摄像头,同时通过ardrone_autonomy连接。以下是我如何实现此目标的代码段。

video_capture = cv2.VideoCapture()

video_capture.open('tcp://192.168.1.1:5555')

vidWidth = video_capture.get(cv2.CAP_PROP_FRAME_WIDTH)

vidHeight = video_capture.get(cv2.CAP_PROP_FRAME_HEIGHT)

您可以看到我正在使用相机的IP地址。当无人机没有通过ROS连接时,这非常类似于网络摄像头。

我的最终目标是使用OpenCV通过使用从相机接收的图像进行跟踪和导航,这意味着我必须发出移动命令(cmd_vel),这需要基于OpenCV接收和处理的图像通过ardrone_autonomy进行连接。

无论如何,我可以通过在连接到ROS时使用无人机的IP摄像头来实现这一目标吗?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

http://wiki.ros.org/video_stream_opencv可以从HTTP / TCP网址打开视频流:

<launch>  <!-- video stream from URL to ROS topic - see http://wiki.ros.org/video_stream_opencv  -->
   <include file="$(find video_stream_opencv)/launch/camera.launch" >        
        <arg name="camera_name" value="drone_webcam" /> <!-- node name and ros graph name -->        
        <arg name="video_stream_provider" value="http://192.168.1.227:8080/video?x.mjpeg" /> <!-- ?x.mjpeg see http://answers.opencv.org/question/13139/cvvideocapture-works-for-webcams-but-not-ip-cameras/ --> 
        <arg name="fps" value="10" /><!-- throttling the querying of frames to 10Hz -->        
        <arg name="frame_id" value="webcam" /> <!-- setting TF frame_id -->         
        <arg name="camera_info_url" value="file:///abc/xyz.yaml" /> <!-- camera info loading, take care as it needs the "file:///" at the start , e.g.:
        "file:///$(find your_camera_package)/config/your_camera.yaml" -->        
        <arg name="flip_horizontal" value="false" /> <!-- flip the image horizontally (mirror it) -->
        <arg name="flip_vertical" value="false" /> <!-- flip the image vertically -->        
        <arg name="visualize" value="true" /> <!-- visualize on an image_view window the stream generated -->
   </include>
</launch>

请注意网址末尾的/video?x.mjpeg