ros-drivers / video_stream_opencv

A package to open video streams and publish them in ROS using the opencv videocapture mechanism
229 stars 160 forks source link

Cannot open video streams with higer numbers #76

Closed grzegorzludwa closed 4 years ago

grzegorzludwa commented 4 years ago

Hi! I have found issue when opening my usb camera stream.

When cameras have index over 10, I can not open them. I always got an error: Could not open the stream.

But using for example ffplay /dev/video12 works fine.

Some basic info:

Roslaunch info:

started roslaunch server http://192.168.69.70:37235/

SUMMARY
========

PARAMETERS
 * /robot_0/camera_2d/back/camera_back/camera_info_url: file:////home/kom...
 * /robot_0/camera_2d/back/camera_back/flip_horizontal: False
 * /robot_0/camera_2d/back/camera_back/flip_vertical: False
 * /robot_0/camera_2d/back/camera_back/fps: 30
 * /robot_0/camera_2d/back/camera_back/frame_id: /robot_0/camera_2...
 * /robot_0/camera_2d/back/camera_back/height: 0
 * /robot_0/camera_2d/back/camera_back/video_stream_provider: 14
 * /robot_0/camera_2d/back/camera_back/width: 0
 * /robot_0/camera_2d/front/camera_front/camera_info_url: file:////home/kom...
 * /robot_0/camera_2d/front/camera_front/flip_horizontal: False
 * /robot_0/camera_2d/front/camera_front/flip_vertical: False
 * /robot_0/camera_2d/front/camera_front/fps: 30
 * /robot_0/camera_2d/front/camera_front/frame_id: /robot_0/camera_2...
 * /robot_0/camera_2d/front/camera_front/height: 0
 * /robot_0/camera_2d/front/camera_front/video_stream_provider: 12
 * /robot_0/camera_2d/front/camera_front/width: 0
 * /robot_0/camera_web_server/address: 0.0.0.0
 * /robot_0/camera_web_server/port: 8080
 * /robot_0/camera_web_server/ros_threads: 4
 * /rosdistro: melodic
 * /rosversion: 1.14.9

NODES
  /robot_0/
    camera_web_server (web_video_server/web_video_server)
  /robot_0/camera_2d/back/
    camera_back (video_stream_opencv/video_stream)
  /robot_0/camera_2d/front/
    camera_front (video_stream_opencv/video_stream)

auto-starting new master
process[master]: started with pid [2583]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to c1ff0b9c-f69a-11ea-9adc-0030180c50e2
process[rosout-1]: started with pid [2595]
started core service [/rosout]
process[robot_0/camera_2d/back/camera_back-2]: started with pid [2598]
process[robot_0/camera_2d/front/camera_front-3]: started with pid [2599]
process[robot_0/camera_web_server-4]: started with pid [2600]
[ INFO] [1600095513.887998462]: Initializing nodelet with 6 worker threads.
[ INFO] [1600095513.890201113]: Initializing nodelet with 6 worker threads.
[ INFO] [1600095514.288111301]: Waiting For connections on 0.0.0.0:8080
[ INFO] [1600095514.389199046]: Camera name: camera
[ INFO] [1600095514.389283225]: Provided camera_info_url: 'file:////home/komp1/catkin_ws/src/malamute_ros/malamute_external_devices/malamute_camera/params/rzezucha_back.yaml'
[ INFO] [1600095514.389340733]: Publishing with frame_id: /robot_0/camera_2d_back
[ INFO] [1600095514.389399940]: Setting camera FPS to: 30
[ INFO] [1600095514.389447129]: Throttling to fps: 30
[ INFO] [1600095514.389485751]: Setting buffer size for capturing frames to: 100
[ INFO] [1600095514.389519968]: Flip horizontal image is: false
[ INFO] [1600095514.389563040]: Flip vertical image is: false
[ INFO] [1600095514.389605951]: Video start frame is: 0
[ INFO] [1600095514.389639989]: Video stop frame is: -1
[ INFO] [1600095514.390394436]: Camera name: camera
[ INFO] [1600095514.390481451]: Provided camera_info_url: 'file:////home/komp1/catkin_ws/src/malamute_ros/malamute_external_devices/malamute_camera/params/rzezucha_front.yaml'
[ INFO] [1600095514.390562002]: Publishing with frame_id: /robot_0/camera_2d_front
[ INFO] [1600095514.390619381]: Setting camera FPS to: 30
[ INFO] [1600095514.390671888]: Throttling to fps: 30
[ INFO] [1600095514.390723763]: Setting buffer size for capturing frames to: 100
[ INFO] [1600095514.390773239]: Flip horizontal image is: false
[ INFO] [1600095514.390834396]: Flip vertical image is: false
[ INFO] [1600095514.390875188]: Video start frame is: 0
[ INFO] [1600095514.390911914]: Video stop frame is: -1
[ INFO] [1600095517.910135412]: camera calibration URL: file:////home/komp1/catkin_ws/src/malamute_ros/malamute_external_devices/malamute_camera/params/rzezucha_back.yaml
[ WARN] [1600095517.912627914]: [camera] does not match name camera_back in file //home/komp1/catkin_ws/src/malamute_ros/malamute_external_devices/malamute_camera/params/rzezucha_back.yaml
[ WARN] [1600095517.912846480]: CV version: 3.2.0
[ INFO] [1600095517.912944932]: Opening VideoCapture with provider: /dev/video14
VIDEOIO ERROR: V4L: index 14 is not correct!
[ INFO] [1600095518.202808537]: Video stream provider type detected: videodevice
[ INFO] [1600095518.202897880]: Backend can't provide camera FPS information
[ERROR] [1600095518.202946847]: Could not open the stream.
[ INFO] [1600095523.969846853]: camera calibration URL: file:////home/komp1/catkin_ws/src/malamute_ros/malamute_external_devices/malamute_camera/params/rzezucha_front.yaml
[ WARN] [1600095523.972285700]: [camera] does not match name camera_front in file //home/komp1/catkin_ws/src/malamute_ros/malamute_external_devices/malamute_camera/params/rzezucha_front.yaml
[ WARN] [1600095523.972506727]: CV version: 3.2.0
[ INFO] [1600095523.972623267]: Opening VideoCapture with provider: /dev/video12
VIDEOIO ERROR: V4L: index 12 is not correct!
[ INFO] [1600095524.174854449]: Video stream provider type detected: videodevice
[ INFO] [1600095524.174965253]: Backend can't provide camera FPS information
[ERROR] [1600095524.175013654]: Could not open the stream.

List of devices:

komp1@lc-desktop:~$ v4l2-ctl --list-devices
Intel(R) RealSense(TM) Depth Ca (usb-0000:00:14.0-1):
    /dev/video0
    /dev/video1
    /dev/video2
    /dev/video3
    /dev/video4
    /dev/video5

Intel(R) RealSense(TM) Depth Ca (usb-0000:00:14.0-2):
    /dev/video6
    /dev/video7
    /dev/video8
    /dev/video9
    /dev/video10
    /dev/video11

HD USB Camera: HD USB Camera (usb-0000:00:14.0-3):
    /dev/video12
    /dev/video13

HD USB Camera: HD USB Camera (usb-0000:00:14.0-4):
    /dev/video14
    /dev/video15

Camera launch file:

<launch>
    <arg name="robot_id" default="/robot_0" />
    <arg name="usb_cam_front" default="12" />
    <arg name="usb_cam_back" default="14" />
    <arg name="fps" default="30" />
    <arg name="front_camera_conf_file" default="rzezucha_front"/>
    <arg name="front_camera_info_url" default="file:///$(find malamute_camera)/params/$(arg front_camera_conf_file).yaml" />
    <arg name="back_camera_conf_file" default="rzezucha_back"/>
    <arg name="back_camera_info_url" default="file:///$(find malamute_camera)/params/$(arg back_camera_conf_file).yaml" />

    <arg name="flip_horizontal" default="false" />
    <arg name="flip_vertical" default="false" />
    <arg name="width" default="0"/>
    <arg name="height" default="0"/>
    <arg name="frame_id_front" default="$(arg robot_id)/camera_2d_front" />
    <arg name="frame_id_back" default="$(arg robot_id)/camera_2d_back" />

    <group ns="$(arg robot_id)/camera_2d/back">
        <node pkg="video_stream_opencv" type="video_stream" name="camera_back" output="screen">
            <remap from="camera" to="image_raw" />
            <param name="video_stream_provider" type="string" value="$(arg usb_cam_back)" />
            <param name="fps" type="int" value="$(arg fps)" />
            <param name="frame_id" type="string" value="$(arg frame_id_back)" />
            <param name="camera_info_url" type="string" value="$(arg back_camera_info_url)" />
            <param name="flip_horizontal" type="bool" value="$(arg flip_horizontal)" />
            <param name="flip_vertical" type="bool" value="$(arg flip_vertical)"/>
            <param name="width" type="int" value="$(arg width)" />
            <param name="height" type="int" value="$(arg height)" />

        </node>
    </group>

   <group ns="$(arg robot_id)/camera_2d/front">
        <node pkg="video_stream_opencv" type="video_stream" name="camera_front" output="screen">
            <remap from="camera" to="image_raw" />
            <param name="video_stream_provider" type="string" value="$(arg usb_cam_front)" />
            <param name="fps" type="int" value="$(arg fps)" />
            <param name="frame_id" type="string" value="$(arg frame_id_front)" />
            <param name="camera_info_url" type="string" value="$(arg front_camera_info_url)" />
            <param name="flip_horizontal" type="bool" value="$(arg flip_horizontal)" />
            <param name="flip_vertical" type="bool" value="$(arg flip_vertical)"/>
            <param name="width" type="int" value="$(arg width)" />
            <param name="height" type="int" value="$(arg height)" />
        </node>
    </group>

    <node pkg="web_video_server" type="web_video_server" name="camera_web_server" output="screen" ns="$(arg robot_id)">
        <param name="port" value="8080" />
        <param name="address" value="0.0.0.0" />
        <param name="ros_threads" value="4" />
    </node>
</launch>
grzegorzludwa commented 4 years ago

I've solved it by myself. The problem was in OpenCV version. I've compiled version 4.5 from source and everythink works fine.