ros-drivers / axis_camera

Contains basic Python drivers for accessing an Axis camera's MJPG stream. Also provides control for PTZ cameras.
BSD 3-Clause "New" or "Revised" License
52 stars 72 forks source link

How to use the driver on several cameras AXIS F10** #66

Closed arizk2605 closed 3 years ago

arizk2605 commented 3 years ago

Hi everyone, I'm currently working on a complete acquisition of several AXIS cameras linked to a F44 switch unit. I managed to run the driver and publish successfully the raw images in the topic /axis/image_raw/compressed and now I'd like to retrieve the images of each camera in different topics simultaneosly to save it into rosbag afterwards. Do you know I could achieve that ? I know that i have to use the url but it seems like the attributes of the axis object are not updated which means the 'camera' attribute remains at 0...

civerachb-cpr commented 3 years ago

Have you tried the f34 branch of this repo? I don't have access to an F44 switch, but that branch did work with an F34 switch with 2 cameras connected to it on a previous project.

arizk2605 commented 3 years ago

Which one is it ? Can you please send me the link ? If I managed to read the raw images i think it should be able to work. The thing is, it works only when I give the hostname directly using the command line "_hostname:=" or by doing it in the script python axis.py. But it seems like the camera info are not extracted. That's why, as i said earlier, the driver doesn't seem to recognize how much cameras are detected. I'm using 2 cameras too.

civerachb-cpr commented 3 years ago

It's a separate branch of this respository: https://github.com/ros-drivers/axis_camera/tree/f34

Just cd into the folder you cloned this git repository into and checkout the f34 branch:

cd catkin_ws/src/axis_camera
git checkout f34
arizk2605 commented 3 years ago

It seems like I was already working with the last version. Can you please show me briefly how you managed to publish each camera data in different topics ?

civerachb-cpr commented 3 years ago

Assuming the camera controller is 192.168.131.10 (change this as required for your application), this should work. Note that the camera parameter corresponds to the physical port ID on the controller unit. In my case, ports 1 and 2 of the F34 were front & rear cameras.

<launch>
  <arg name="camera_host"  default="192.168.131.10" />
  <arg name="front_camera_port" default="1" />
  <arg name="rear_camera_port" default="2" />

  <include file="$(find axis_camera)/launch/axis.launch">
    <arg name="camera_name" value="front_camera" />
    <arg name="hostname" value="$(arg camera_host)" />
    <arg name="enable_theora" value="0" />
    <arg name="enable_ptz" value="0" />
    <arg name="enable_ptz_teleop" value="0" />
    <arg name="width" value="640" />
    <arg name="height" value="480" />
    <arg name="camera" value="$(arg front_camera_port)" />
  </include>

  <include file="$(find axis_camera)/launch/axis.launch">
    <arg name="camera_name" value="rear_camera" />
    <arg name="hostname" value="$(arg camera_host)" />
    <arg name="enable_theora" value="0" />
    <arg name="enable_ptz" value="0" />
    <arg name="enable_ptz_teleop" value="0" />
    <arg name="width" value="640" />
    <arg name="height" value="480" />
    <arg name="camera" value="$(arg rear_camera_port)" />
  </include>
</launch>
arizk2605 commented 3 years ago

Thank you so much ! i'll try it and give you a feedback :) I prefer using python scripts and then execute the node using rosrun because roslaunch tend to bug from time to Time in my raspberry ( i'm working on it via ssh) . Do you have any Idea how i could do that using this kind of method ? If not, how can i record simultaneosly on rosbag using the launch file ?

civerachb-cpr commented 3 years ago

You can use rosrun axis_camera axis.py and provide the parameters from above if you want, though I've never had any problems using launch files.

If you're running over ssh you can use the nohup command to prevent the process from hanging up if you get disconnected. Or you can use screen to open a persistent background shell that you can safely disconnect from and keep any processes launched from it running.

To start recording a bag from a launch file, you can follow the process described here: https://answers.ros.org/question/52773/record-with-rosbag-from-launch-file/

arizk2605 commented 3 years ago

Hi, I run a launch file using the code you gave me above and it displayed this :

_PARAMETERS

NODES /front_camera/ axis (axis_camera/axis.py) /rear_camera/ axis (axis_camera/axis.py)

ROS_MASTER_URI=http://localhost:11311

process[front_camera/axis-1]: started with pid [1615] process[rearcamera/axis-2]: started with pid [1616]****

However, I couldn't find the topics where the raw images were published. I used to find it by listening to "axis/image_raw/compressed" by running "rosrun axis_camera axis.py" simultaneosly.

Which topics do I have to listen to ? So that i can record them in rosbags afterwards.

civerachb-cpr commented 3 years ago

Instead if axis/* the topics should be front_camera/* and rear_camera/*. Running rostopic list will show you the complete list of topics available.

arizk2605 commented 3 years ago

Yes ! Thank you so much. I tried adding some lines to record into rosbags :

**_<node pkg="rosbag" type="record" name="rosbag_record_camera1" args="record /front_camera/image_raw/compressedcamera1 -o $(arg axis_camera/bag1 --split --durat$

<node pkg="rosbag" type="record" name="rosbag_record_camera2" args="record /front_camera/image_raw/compressedcamera2 -o $(arg axiscamera/bag2 --split --durat$**

I think it works fine but I can't find the rosbags. The problem is the output directory... Do you know how i could save them into a specific directory (for example simply the folder /axis_camera) ?

civerachb-cpr commented 3 years ago

It's hard to say, sicne in what you've pasted above the args parameter is truncated, and I can't actually see the value of your axis_camera arg.

From rosbag record --help you can see

 -O NAME, --output-name=NAME
                        record to bag with name NAME.bag

So adding e.g. -O /home/administrator/camera1.bag should do what you need. Be aware though that recording image and pointcloud data to a bag can very quickly consume large amount of disk space. So make sure to clean up old bags, or instead of adding the record nodes to the launch file, run them manually with the rosbag record ... command only when you actually need to record data.

arizk2605 commented 3 years ago

It worked ! Thank you so much for your help !

civerachb-cpr commented 3 years ago

Glad you got it working.