OpenCV difference between roslaunch and rosrun
OS: Ubuntu 16.04.2 LTS Xenial
ROS: Kinetic.
OPenCV: 3.2.0-dev
Python 2.7.12
ROS_ROOT=/opt/ros/kinetic/share/ros
ROS_PACKAGE_PATH=/home/odroid/ros_ws/src:/opt/ros/kinetic/share
ROS_MASTER_URI=http://localhost:11311
ROSLISP_PACKAGE_DIRECTORIES=/home/odroid/ros_ws/devel/share/common-lisp
ROS_DISTRO=kinetic
ROS_ETC_DIR=/opt/ros/kinetic/etc/ros
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__
camera=cv2.VideoCapture("/dev/video8")
print camera
if not camera.isOpened():
camera=None
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]
3.2.0-dev
<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
killed
3.2.0-dev
<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.
If is a usb camera you will try to use usb_cam package.