访问无人机连接到R时带有OpenCV的摄像头

2024-10-01 00:14:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个问题,我无法连接到AR无人机2相机时,无人机是通过ROS连接使用阿德罗龙自主阿德罗。发射. 在

我认为问题是因为我试图通过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摄像头来完成这一任务?在

谢谢你的帮助!在


Tags: 图像getvideoroscv2frameopencv摄像机
1条回答
网友
1楼 · 发布于 2024-10-01 00:14:55

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

<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>

注意URL末尾的/video?x.mjpeg。在

相关问题 更多 >