YarpTricks

From Wiki for iCub and Friends
Revision as of 14:54, 28 July 2010 by Jgvictores (talk | contribs) (Grabbing video streams)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Record/replay bottles

  • How to record bottles from a YARP port to a file (while still looking at them):
   $ yarp read /port/to/read/from | tee filename
  • How to replay bottles from a file to a YARP port:
   $ IFS=$'\n'       # a bottle per line
   $ DELAY=0.1       # delay between bottles (in seconds)
   $ for l in `cat filename`; do echo "$l"; sleep $DELAY; done | yarp write /port/to/write/to

Permanent connections

(need to turn on CREATE_YARPSERVER3 in cmake, and use yarpserver3 instead or usual yarp server)

Instead of:

 yarp connect /icubSim/cam/left /my/viewer

do:

 yarp connect --persist /icubSim/cam/left /my/viewer

Then a connection will be made whenever both /icubSim/cam/left and /my/viewer exists.

You can also do ROS-like topic connections:

 yarp connect /icubSim/cam/left topic://images
 yarp connect topic://images /my/viewer

This has the same effect. It can also connect multiple output ports to multiple input ports

Grabbing video streams

OpenCV (ffmpeg too, actually) can grab videos even if they're streaming and/or not local. Just open it as a standard file with it's full URL! Here's an example wrapping an AXIS IP camera stream (found the stream file just moving around the file system through telnet) with opencv_grabber:

yarpdev --device opencv_grabber --movie http://IP_ADDRESS/mjpg/video.mjpg

If the site has basic authentication, you can to embed your userID and password by:

yarpdev --device opencv_grabber --movie http://userID:pass@IP_ADDRESS/mjpg/video.mjpg

Now it should be available on the /grabber port!