Rosanswers logo

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="whisker_sensor.py" 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 whisker_sensor.py
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.

Originally posted by graeme on ROS Answers with karma: 46 on 2018-01-25

Post score: 1

Original comments

Comment by rdelgadov on 2018-01-26:
If is a usb camera you will try to use usb_cam package.


1 Answer 1


Rosanswers logo

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.

Originally posted by graeme with karma: 46 on 2018-01-31

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.