Ucamserver

From Rsewiki

Introduction

Intended for image handling functions.

The following camera-related plug-ins are available:

  • Camera control (camget, camset etc)
  • Image access (imageget, imageset) access to fresh images.
  • Image pool handling (poolget poollist etc.) pool of imege buffers with image handling functionality.
  • Guidemark detection (gmkget) giudemark 3D pose and code
  • Road outline plugin (pathget) polygon with road outline matching a seed area.
  • Sample plugin (center of gravity)

The following cameras are supported:

  • all USB cameras supported by the pwc (Philips Web Cam) driver, e.g.
  • - Philips 740K, 840K,
  • - Logitech Orbit
  • A few frame-grapper cards (I have not tried for a long time)
  • IEEE1394 DCI-standard
  • IEEE1394 DVI - not supported
  • palantir streaming video - not supported p.t.

Run the server

Run the server in a directory with a configuration file (ucamserver.ini)

ucamserver

It then shows a command prompt:

>>

To monitor images and results use the monitoring client UCLIENT or AUCLIENT (or the server console directly - or as a last resort TELNET)

See:

>> module list

For further help about the server and a list of all available commands (from all plug-ins) use:

>> help

Each of the listed commands should have an on-line help function, e.g:

>> camset help

Typical configuration SMR

A camera server configuration (ucamserver.ini) for the SMR could be:

do cmd="mkdir -p log_ucamserver"
server imagepath="log_ucamserver"
server datapath="log_ucamserver"
server replayPath="log"
server port=24920
#
module load=var
module load=gmk
module load=odopose
module load=aupoly.so.0
# log odometry (as seen by ucamserver)
odopose log
module load="aukinect.so.0"
var kinect.desiredframerate=3
kinect open
# convert to BGR (default is Bayer GRBG)
poolpush img=18 cmd="poolget toimg=22 fmt=BGR silent"
# log kinect (RGB) images (every other image (i=2))
poolset img=22 log i=2
# ballfinder - see 'ball help' and 'var ball' for info
module load="auball.so.0"
# use the image to find balls every 3 images.
poolpush img=22 i=3 cmd="ball blue debug='true'"


Logfile for odometry and used images will then be produced in datapath, and the images saved in the imagepata.

Move them (including imgpool.log) into a subdirectory, e.g. log_ucamserver/log/ for replay.

Image recording

The imagelog can be opened with an ini-script or commands like:

>> server imagepath="/home/chr/chr/results"
>> server datapath="/home/chr/chr/results"
>> camset device=1 log
Logfile renamed OK: mv /home/chr/chr/results/image.log /home/chr/chr/results/image20110502_125734.logg
Logging images to /home/chr/chr/results/image.log
<camset info="done"/>
>> camset device=0 log
<camset info="done"/>

all used images from device 0 and 1 are saved (to 'imagepath') with timestamp and filename saved to 'image.log' (in the 'datapath') file (see log file format below).

Images from more than one camera can be logged in this way, e.g.:

>> campush device=0 i=10 cmd="imageget silent"
>> campush device=1 i=10 cmd="imageget silent"

For the stereo camera of the GUPPY type, the cameras should be connected with a trigger cable. and both cameras set to external trigger, like:

>> camset device=10 gain=auto shutter=auto
>> camset device=11 gain=auto shutter=auto
>> camset device=10 triggerExt=true;
>> camset device=11 triggerExt=true;
>> campush device=10 cmd="imageget silent"
>> campush device=11 cmd="imageget silent"

Then trigger both cameras with a regular command like:

>> push t=0.5 cmd="camset device=11 trigger"

To trigger new images at a rate of 2Hz (t=0.5) in this case.

NB! the logging of images to a disk file takes time, so keep frame rate down. An alternative could be to let the imagepath point to a RAM-disk, and (tar) pack and move the files to a disk file at regular intervals. This seems to be much less demanding than to save all images directly to disk. There is an example of this solution in the bin/config_hako2 directory, using the aucron.so.0 plugin to trigger a bash script, like:

>> cron t=11 cmd="bash move-to-usbdisk '/mnt/ram/svs*' /rhome/demo/log"

This takes all files on the ram-disk that matches '/mnt/ram/svs*' and packs the files to a disk file at '/rhome/demo/log'. The bash script 'move-to-usbdisk' is in the 'bin/conf_hako2' directory too.


To close the logging of images from a specific camera use

>> camset device=10 log=false

or by setting the log-flag directly:

>> var campool.device10.log=0

To close the log file for all cameras use the command

>> imageget log=false
Closed image snapshot log /home/demo/results/image.log

Unpack of packed imagelog

If 'move-to-usb' were used to save to disk, then the bash script 'unpack-tars' may be used (in the directory with the tar-files):

#!/bin/bash
files="$(ls *.bmp.tar 2>/dev/null)" 
# declare integer variables
declare -i cnt=0
for X in $files
do
  tar -xf $X
  cnt=$cnt+1
done

The images are then available for replay.


Images to mpeg video

The images can be packed into a video sequence using a script. If images from more than one camera is used, then it may be a good idea to make an empty directory and link all the images from one of the cameras to this directory first, e.g.:

mkdir left
cd left
ln -s ../*__10* .

A script like this may then be used to pack them into a video sequence:

#! /bin/bash
let COUNTER=1000000
for f in $( ls imgC/*.bmp ); do 
  echo convert $f imgCpng/hako-20080821-left-$COUNTER.png
  convert $f imgCpng/hako-20080821-left-$COUNTER.png
  let PREV=$COUNTER
  let COUNTER+=1
  done
# convert to mpeg format
# -r 10 frames per second
# -b 5000000 bitrate på 5Mbit/sec
# -y betyder overskriv destination
ffmpeg -y -r 25 -b 5000000 -i imgCpng/hako-20080821-left-1%06d.png path.mpeg
ls -l *.mpeg

The script list all files files - in this case all *.bmp files - then converts them to *.png format, and - most important - adds a number to the filename, that will be the image sequence in the video.

The ffmpeg will do the rest, with the parameters as shown.

Replay configuration

Make a directory for the replay configuration, e.g. replay/ballfinder:

mkdir ~/replay/ballfinder
cd ~/replay/ballfinder

place a copy of the cameraserver configuration file ucamserver.ini in this directory.

Make a subdirectory in this directory, e.g. called log

mkdir log
cd log

Place the logfiles (odoPose.log and image.log) in this directory

cp <sourcedir>/*.log .

Make a further subdirectory for the images, this directory MUST be called imgorg

mkdir imgorg
cp <imagepath>/*.png imgorg/

The ucamserver.ini need to be modified slightly to enable the replay:

server dataPath="/vhome/jca/logfiles"
server imagepath="/vhome/jca/logfiles/imgorg"
server replayPath="/vhome/jca/replay/ballfinder"              <--- new
module load=var
module load=gmk
module load=odopose
odopose replay                                                <--- new
# odopose log                                                 <--- changed to comment
# camera parameters for GUPPY camera (device 10)
camset device=10 focallength=650
camset device=10 posx=0.4 posy=0.0 posz=0.87 rotphi=0.3
camset device=10 replay                                       <--- new
module load=path
# ballfinder and configuration
module load="./aub2.so.0"
var b2.redlim="105 127 129 180"
var b2.bluelim="115 200 95 132"
var b2.ballsize=0.12
var b2.topline=75
var b2.minsize=20
var b2.maxsize=65
# log images from device 10
# camset device=10 log=false                                  <--- changed to comment
# use an image every 1.5 seconds (image is logged and available in image pool)
# push t=1.5 cmd="imageget img=10"                            <--- changed to comment
# use the image to find balls every time image 10 is updated
poolpush img=10 cmd="ball blue debug='true'"

Then the replay can commence, first start the camera server in the configuration directory

cd ~/replay/ballfinder
ucamserver 

When the cameraserver is started, then the stepping can start

>> camset step
<camset info="Stepped to 1266588079.109762 line 2 in image.log"/>
Ball position  x:   4.1385  y:   0.5525  z:   0.2767
>>

This will advance to the next image in the logfile, and some messages may be printed on the console. The image will be loaded into the image-pool with the same image number as the original device number (here 10).

The odometry pose may be stepped too:

>> odopose step
<odopose tod="1266588094.529696" time="15:01:34.529" logLine="2"/>
>>

This may advance the image.log file too (to the same log-time), and thus trigger another image and any command related to that image.

Image.log file format

The image log file has one line per image, like:

1287579606.142885 159 120 160 1050.00 2 0.000 0.000 0.000 0.0000 0.0000 0.0000 img00000159-cam02-20101020_150006.142.png
1287579608.842862 186 120 160 1050.00 2 0.000 0.000 0.000 0.0000 0.0000 0.0000 img00000186-cam02-20101020_150008.842.png
1287579609.642899 194 120 160 1050.00 2 0.000 0.000 0.000 0.0000 0.0000 0.0000 img00000194-cam02-20101020_150009.642.png
1287579610.242894 200 120 160 1050.00 2 0.000 0.000 0.000 0.0000 0.0000 0.0000 img00000200-cam02-20101020_150010.242.png

and the following format on each line:

  • timestamp (seconds since 1 jan 1970)
  • image serial number
  • image height
  • image width
  • camera focal length in pixels (as set in camera configuration file ucamserver.ini)
  • camera device number (here device 2)
  • camera x pose relative to robot (forward)
  • camera y pose relative to robot (left)
  • camera z pose relative to robot (up)
  • camera Omega Rotation (in radians) around x-axis
  • camera Phi Rotation (in radians) around y-axis
  • camera Kappa Rotation (in radians) around z-axis
  • image filename

Odometry logfile format

The odopmetry - as well as the map and utm logfiles has the following format:

1266588182.049364 0.593 0.114 0.46900 0.000 -1 1266588182.049630
1266588182.119369 0.604 0.119 0.48700 0.000 -1 1266588182.119790
1266588182.189390 0.614 0.125 0.50450 0.000 -1 1266588182.189852
1266588182.269268 0.625 0.131 0.52320 0.000 -1 1266588182.269529
1266588182.457870 0.647 0.144 0.56050 0.000 -1 1266588182.458362

With the following meaning

  • timestamp in seconds (when the data is assumed to be valid)
  • x-position in meters
  • y-position in meters
  • heading in radians
  • velocity in m/s
  • data quality (if any)
  • data source (update source, -1 is from MRC using the MRC connection to the server)
  • additional timestamp (when the data was put into the logfile)