Table of Contents
Text WebCam Support
Introduction
This functionality is especially of interest for monitoring invisible spots on the layout, for example shadow stations.
USB WebCams can be used and are low priced; High Definition WebCams are not needed for this purpose. For testing purpose a Logitech C170 has been used which comes for about €20,-.
Rocview will not show the WebCam as a movie but as still pictures with a definable refresh interval which is OK to see what is happening.
An external capturing program is needed to provide the still pictures to make this functionality for Rocrail Operating System independent; See the Script paragraph.
Text Setup
The content of the text object must point to the WebCam picture.
The Refresh time in ms must have a value of at least 100. A good value is 500.
Resizing of the text object can be done with the cx and cy grid values on the General tab.
Capturing Script
Replace <username> with your username.
macOS
The tool WACAW is used on a Mac to capture a still picture of a WebCam.
#!/bin/bash while : do if [ ! -f /Users/<username>/webcam1/picture.png ]; then echo "Snapping a new picture of the webcam..." ./wacaw -d 2 --png /Users/<username>/webcam1/_picture mv /Users/<username>/webcam1/_picture.png /Users/<username>/webcam1/picture.png fi sleep 0.25 done
(Do not forget to make this new script executable with chmod +x webcam1.sh.)
If the color of the captured pictures is bad the -n parameter must be used:
./wacaw -d 2 -n 5 --png /Users/rob/webcam1/picture
Detecting the device number
With the -L command line option the device list ist shown:
./wacaw -L There are 3 devices in the list. The current selection is 2. 0 - DV Video [is available] [has no inputs] 1 - IIDC FireWire Video [is available] [has no inputs] 2 - USB Video Class Video [is available] [has inputs] There are 1 inputs for this device (2). The current selection is 0. 0 - Webcam C170 [is available]
In this example the device number to use is 2: -d 2.
Linux
Under Linux the ffmpeg tool can be used to capture pictures:
sudo apt install ffmpeg
#!/bin/bash while : do if [ ! -f /home/<username>/webcam1/picture.png ]; then echo "Snapping a new picture of the webcam..." ffmpeg -f video4linux2 -i /dev/video1 -frames 1 /home/<username>/webcam1/_picture.png mv /home/<username>/webcam1/_picture.png /home/<username>/webcam1/picture.png fi sleep 0.25 done
Devices
With
ls /dev/video*
a list of video devices will be shown.
If the PC/Laptop ha a build-in camera this will show up as /dev/video0.
The first external WebCam will be in this case /dev/video1.
Windows
This script has not been tested and uses Irfanview as capture tool.
:startallover IF NOT exist "C:\webcam1\picture.png"\ ( REM Change the Twain Source REM http://www.gssezisoft.com/Products/CmdTwain/Download/SetTwainSource.zip REM cscript.exe SetTwainSource.vbs driver i_view32.exe /scanhidden /dpi=(150,150) /convert="C:\webcam1\picture.png" ) ping -n 1 127.0.0.1 > NULL GOTO startallover
Alternative
The folowing Batch script used commandcam.exe for grabbing and bmp2png.exe for picture converting and was successful tested.
- Download:
- https://batchloaf.wordpress.com/commandcam/ → Download and Documentation
- http://sourceforge.net/projects/pmt/files/bmp2png/1.6.2/b2p162d.zip/download → Extract BMP2PNG.EXE from the ZIP file (also for Win 10)
This files require less resources than IrfanView.
echo off :start if exist picture.png goto start commandcam.exe /quiet /filename picture.bmp /delay 10 bmp2png.exe -Q picture.bmp goto start
Remark: The code above need that all files are placed in the same folder.
Otherwise, the path information corresponding to the different directories have to be supplemented.
Informations to the installed video hardware may so be requested:
commandcam.exe /devlistdetail
If multiple video devices are installed, an additional option can select the device.
In this example the device number "2":
... commandcam.exe /quiet /filename picture.bmp /delay 10 /devnum 2 ...
File Handshake
Only one at a time of both programs, wacaw (or any other capturing program) and Rocview, should access the picture file to avoid invalid images.
- The script will capture a picture and store it in the picture.png file.
- Rocview will read and show it.
- Rocview deletes the picture.png.
- The script detect that the picture.png is deleted and will capture the next picture of the WebCam.
- Goto step 2…