Ask Your Question
1

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
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.

edit retag flag offensive close merge delete

Comments

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

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

1 Answer

Sort by » oldest newest most voted
0

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:

https://answers.ros.org/question/2198...

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 198 times

Last updated: Jan 31 '18