ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

OpenCV difference between roslaunch and rosrun

asked 2018-01-25 15:22:22 -0500

graeme gravatar image
OS: Ubuntu 16.04.2 LTS Xenial
ROS: Kinetic.
OPenCV: 3.2.0-dev
Python 2.7.12

If I run a python script through a launch file, OpenCV cannot open a camera, but running it manually openCV works fine.

Here’s the bare bones Code Snippet where it works/fails.

 print cv2.__version__
   print camera
   if not camera.isOpened():
       print "No camera"
   return camera

Here’s the line from the launch file:

<node name="whisker_sensor" pkg="ros_whisker_sensor" type="" respawn="false" output="screen"/>

Here’s the output of the screen dump from that launch:

process[whisker_sensor-10]: started with pid [32257]
<VideoCapture 0xb6d487b0>
No camera

Notice it sets up a camera Object, but it fails to open.

However if I kill the specific node and then re-run it manually from a rosrun command: like this:

odroid@fish01:~$ rosnode kill /whisker_sensor ; rosrun ros_whisker_sensor
killing /whisker_sensor
<VideoCapture 0xb6d017b0>
136 0.723058982284
136 0.723058982284
134 0.731470868094

It passes the isOpened() check and starts dumping the data I’m looking for from a processed image.

Does anyone have any thoughts as to why camera.isOpened() fails under a roslaunch but works under a rosrun? Is there any way I can get more informative information out of the camera function? I have a feeling its a path or library issue, but I can't figure out what's different between the launch file and run approaches.

edit retag flag offensive close merge delete


If is a usb camera you will try to use usb_cam package.

rdelgadov gravatar image rdelgadov  ( 2018-01-26 07:53:16 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-01-31 15:40:42 -0500

graeme gravatar image

I ended up installing usb_cam as suggested,(I'm going to use it eventually) but in the process discovered the solution from a problem someone else had with usb_cam:

The camera code needs to have un-restricted access to the /dev/video## ports.

by doing this:

 sudo chmod a+rwx /dev/video*

Prior to starting the ros stack, my ros code has access to the camera. I added this chmod to my start up script and I'm all set.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2018-01-25 15:22:22 -0500

Seen: 542 times

Last updated: Jan 31 '18