ros-drivers / gscam

ROS Camera driver for GStreamer-based video streams.
142 stars 174 forks source link

Add an example launchfile which works for standard cameras on OS X #14

Closed kubark42 closed 10 years ago

kubark42 commented 10 years ago

As a result of resolving issue #13 (problems compiling on OSX), I came across this second problem. When launching gscam image_raw and camera_info topics are not published. The only published topic is the gscam node itself, which in this case is still called "/v4l/gscam_driver_v4l".

Note that the hardware seems to be active, so it might be that I haven't launched all necessary processes. I'm currently running only roscore and gscam.

jbohren commented 10 years ago

Can you post the contents of your launchfile?

kubark42 commented 10 years ago
<launch>
  <!-- This launchfile should bring up a node that broadcasts a ros image
       transport on /webcam/image_raw -->

  <arg name="DEVICE" default="/dev/video0"/>
  <!-- The GStreamer framerate needs to be an integral fraction -->
  <arg name="FPS" default="30/1"/>
  <arg name="PUBLISH_FRAME" default="false"/>

  <node ns="v4l" name="gscam_driver_v4l" pkg="gscam" type="gscam" output="screen">
    <param name="camera_name" value="default"/>
    <param name="camera_info_url" value="package://gscam/examples/uncalibrated_parameters.ini"/>
    <param name="gscam_config" value="qtkitvideosrc device=$(arg DEVICE) ! video/x-raw-rgb,framerate=$(arg FPS) ! ffmpegcolorspace"/>
    <param name="frame_id" value="/v4l_frame"/>
    <param name="sync_sink" value="true"/>
  </node>

  <node if="$(arg PUBLISH_FRAME)" name="v4l_transform" pkg="tf" type="static_transform_publisher" args="1 2 3 0 -3.141 0 /world /v4l_frame 10"/>
</launch>

This is v4l.launch where "v4l2src" is replaced by "qtkitvideosrc".

jbohren commented 10 years ago

In gscam_config try replacing device=$(arg DEVICE) with device-index=$(arg DEVICE) and then up above, replace /dev/video0 with 0 or 1.

jbohren commented 10 years ago

Also, it looks like qtkitvideosrc doesn't support video/x-raw-rgb: https://github.com/timvideos/gst-plugins-bad/blob/master/sys/applemedia/qtkitvideosrc.m#L40

Can you run (and post the output of) the following:

gst-inspect qtkitvideosrc
gst-inspect osxvideosrc
kubark42 commented 10 years ago

In gscam_config try replacing device=$(arg DEVICE) with device-index=$(arg DEVICE) and then up above, replace /dev/video0 with 0 or 1.

Doesn't seem to have any effect. I can still type whatever in the place of /dev/video0 and it will still run, using the primary camera.

kubark42 commented 10 years ago
~/Documents/catkin_ws$ gst-inspect qtkitvideosrc
Factory Details:
  Long name:    Video Source (QTKit)
  Class:    Source/Video
  Description:  Reads frames from a Mac OS X QTKit device
  Author(s):    Ole André Vadla Ravnås <oravnas@cisco.com>
  Rank:     primary (256)

Plugin Details:
  Name:         applemedia
  Description:      Elements for capture and codec access on Apple OS X and iOS
  Filename:     /usr/local/lib/gstreamer-0.10/libgstapplemedia.so
  Version:      0.10.23
  License:      LGPL
  Source module:    gst-plugins-bad
  Source release date:  2012-02-20
  Binary package:   GStreamer
  Origin URL:       http://gstreamer.net/

GObject
 +----GstObject
       +----GstElement
             +----GstBaseSrc
                   +----GstPushSrc
                         +----GstQTKitVideoSrc

Pad Templates:
  SRC template: 'src'
    Availability: Always
    Capabilities:
      video/x-raw-yuv
                 format: UYVY
                  width: 640
                 height: 480
              framerate: [ 0/1, 100/1 ]
        pixel-aspect-ratio: 1/1
      video/x-raw-yuv
                 format: UYVY
                  width: 160
                 height: 120
              framerate: [ 0/1, 100/1 ]
        pixel-aspect-ratio: 1/1
      video/x-raw-yuv
                 format: UYVY
                  width: 176
                 height: 144
              framerate: [ 0/1, 100/1 ]
        pixel-aspect-ratio: 12/11
      video/x-raw-yuv
                 format: UYVY
                  width: 320
                 height: 240
              framerate: [ 0/1, 100/1 ]
        pixel-aspect-ratio: 1/1
      video/x-raw-yuv
                 format: UYVY
                  width: 352
                 height: 288
              framerate: [ 0/1, 100/1 ]
        pixel-aspect-ratio: 12/11

Element Flags:
  no flags set

Element Implementation:
  Has change_state() function: gst_qtkit_video_src_change_state
  Has custom save_thyself() function: gst_element_save_thyself
  Has custom restore_thyself() function: gst_element_restore_thyself

Element has no clocking capabilities.
Element has no indexing capabilities.
Element has no URI handling capabilities.

Pads:
  SRC: 'src'
    Implementation:
      Has getrangefunc(): gst_base_src_pad_get_range
      Has custom eventfunc(): gst_base_src_event_handler
      Has custom queryfunc(): gst_base_src_query
      Has getcapsfunc(): gst_base_src_getcaps
      Has setcapsfunc(): gst_base_src_setcaps
      Has acceptcapsfunc(): gst_pad_acceptcaps_default
      Has fixatecapsfunc(): gst_base_src_fixate
    Pad Template: 'src'

Element Properties:
  name                : The name of the object
                        flags: readable, writable
                        String. Default: "qtkitvideosrc0"
  blocksize           : Size in bytes to read per buffer (-1 = default)
                        flags: readable, writable
                        Unsigned Long. Range: 0 - 18446744073709551615 Default: 4096 
  num-buffers         : Number of buffers to output before sending EOS (-1 = unlimited)
                        flags: readable, writable
                        Integer. Range: -1 - 2147483647 Default: -1 
  typefind            : Run typefind before negotiating
                        flags: readable, writable
                        Boolean. Default: false
  do-timestamp        : Apply current stream time to buffers
                        flags: readable, writable
                        Boolean. Default: false
  device-index        : The zero-based device index
                        flags: readable, writable
                        Integer. Range: -1 - 2147483647 Default: -1 

--and--

~/Documents/catkin_ws$ gst-inspect osxvideosrc
No such element or plugin 'osxvideosrc'
kubark42 commented 10 years ago

Also, it looks like qtkitvideosrc doesn't support video/x-raw-rgb: https://github.com/timvideos/gst-plugins-bad/blob/master/sys/applemedia/qtkitvideosrc.m#L40

I changed the gscam_config parameter to have video/x-raw-yuv, which is supported according to the above file, but I didn't see a change in behavior.

jbohren commented 10 years ago

I changed the gscam_config parameter to have video/x-raw-yuv, which is supported according to the above file, but I didn't see a change in behavior.

how about video/x-raw-yuv,framerate=$(arg FPS),width=640,height=480

kubark42 commented 10 years ago

Still the same results. However, I notice that in both cases if I am looking at the video stream through another program, that starting gscam causes the video stream to change format to 640x480. So things are definitely happening, I'm just not sure what.

Is normal procedure for the gscam topic to appear, as well as the other two topics? Is it sensible to query the gscam topic in hopes that the video data is published there?

jbohren commented 10 years ago

Is normal procedure for the gscam topic to appear, as well as the other two topics? Is it sensible to query the gscam topic in hopes that the video data is published there?

I assumed that you weren't seeing any images on those topics. When you bring up rosrun rqt_image_view rqt_image_view do you see anything at all?

kubark42 commented 10 years ago

Oh, pardon my ignorance. I was working off the camera calibration tutorial and:

09:10:30 ~/Documents/catkin_ws$ rosnode list
/rosout
/v4l/gscam_driver_v4l
09:10:33 ~/Documents/catkin_ws$

left me thinking that there were no other topics published. However, loading up rosrun rqt_image_view rqt_image_view shows me video! So the last thing to figure out is how to select the right camera.

jbohren commented 10 years ago

So the last thing to figure out is how to select the right camera.

Cool! I'd expect that device-index to work if you try setting it to 0,1,2 etc


w.r.t. listing topics, you want to run rostopic list. I should have asked about that when you mentioned that the topics weren't showing up.

kubark42 commented 10 years ago

Cool! I'd expect that device-index to work if you try setting it to 0,1,2 etc

Alas, that part is remaining stubborn. I have two cameras on my system, but even going to "3" makes no difference. I would have expected it to fail when I typed in random garbage for the address, but it simply seems to ignore that part of the config line.

Note: if I change the video back to rgb it freezes, as well as if I pass an incorrect width or height. It's parsing that line, it's just the video device that's being ignored.

kubark42 commented 10 years ago

@jbohren I figured out what you were saying earlier. I was replacing "/dev/video0" by "dev/video1". However, you were suggesting "0" or "1", which does work. So thanks, it's 100% functional now. I'll submit a patch soon.

kubark42 commented 10 years ago

One thing I'm still having a little trouble with is figuring out "set_camera_info". The directions at http://wiki.ros.org/camera_calibration/Tutorials/MonocularCalibration indicate

rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/camera/image_raw camera:=/camera

which I change to reflect that the camera is published on "/qtkit". However, I still get an error:

~/Documents/catkin_ws$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/qtkit/camera/image_raw camera:=/qtkit/camera
('Waiting for service', '/qtkit/camera/set_camera_info', '...')
Service not found

Is there a way for me to verify that gscam is publishing the set_camera_info topic?

jbohren commented 10 years ago

Is there a way for me to verify that gscam is publishing the set_camera_info topic?

set_camera_info is a service which gscam serves. You should see it listed under rosservice list.

kubark42 commented 10 years ago

Perfect. That made it clear to me that the appropriate command was ~/Documents/catkin_ws$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/qtkit/camera/image_raw camera:=/qtkit/

jbohren commented 10 years ago

Perfect. That made it clear to me that the appropriate command was ~/Documents/catkin_ws$ rosrun camera_calibration cameracalibrator.py --size 8x6 --square 0.108 image:=/qtkit/camera/image_raw camera:=/qtkit/

Yeah, you can blame me for that. It should be /qtkit/camera/set_camera_info. I've been meaning to fix that for a while. It's patched in 486c1a3, but I need to check with some other people since it might break code for people who are using the current service.

kubark42 commented 10 years ago

Does gscam also publish /camera/camera_info? https://github.com/uzh-rpg/rpg_monocular_pose_estimator/blob/master/monocular_pose_estimator/src/monocular_pose_estimator.cpp#L34 wants to subscribe to a node named as such.

jbohren commented 10 years ago

Does gscam also publish /camera/camera_info?

Yes it does. It publishes camera/camera_info within whatever namespace you create the node. In the osx launchfile you submitted, this namespace is /qtkit, so it will be /qtkit/camera/camera_info

kubark42 commented 10 years ago

Got it. The problem was that the code I'm trying to use was looking for these in a hard-coded place. I'm now able to visualize the output:

screen shot 2014-05-21 at 12 08 00 am

Thanks a million, @jbohren. I really appreciate you bearing with me as I worked through this.