User Tools

Site Tools


text:text-webcam-en

Differences

This shows you the differences between two versions of the page.


text:text-webcam-en [2023/01/15 07:46] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== Text WebCam Support ======
 +[[:english#objects|{{  :objects.png}}]][[:english|{{  :rocrail-logo-35.png}}]]
 +[[:english|Content]] -> [[:english#objects|Objects]] ->   **[[:text-en|Text]]** 
 +  * **[[:text:text-webcam-en|WebCam]]** | [[:text:text-webcam-server-en|WebCam on Server]]
  
 + \\
 +
 +=====Introduction=====
 +{{ http://www.logitech.com/assets/36163/webcam-c170-glamour-image-lg.png?0x200}}
 +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 [[http://www.logitech.com/de-de/product/webcam-c170|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 __**[[#capturing_script|Script paragraph]]**__.\\
 +
 + \\
 +
 +=====Text Setup=====
 +{{:text:text-webcam-2-en.png}}\\
 +
 +The content of the text object must point to the WebCam picture.\\
 +The __**[[:text-en#refresh|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.\\
 +{{:text:text-webcam-size-en.png?400}}\\
 + \\
 +
 +=====Capturing Script=====
 +Replace <username> with your username.\\
 +====macOS====
 +The tool [[http://webcam-tools.sourceforge.net|WACAW]] is used on a Mac to capture a still picture of a WebCam.\\
 +<code bash>
 +#!/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
 +</code>
 +(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:
 +<code bash>
 +    ./wacaw -d 2 -n 5 --png /Users/rob/webcam1/picture
 +</code>
 + 
 + \\
 +===Detecting the device number===
 +With the **-L** command line option the device list ist shown:
 +<code>
 +./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]
 +</code>
 +In this example the device number to use is 2: **-d 2**.\\
 +
 + \\
 +
 +====Linux====
 +Under Linux the **ffmpeg** tool can be used to capture pictures:
 +<code>
 +sudo apt install ffmpeg
 +</code>
 +<code bash>
 +#!/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
 +</code>
 +===Devices===
 +With
 +<code>
 +ls /dev/video*
 +</code>
 +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====
 +  * https://github.com/tedburke/CommandCam/blob/master/CommandCam.exe
 +
 +This script has not been tested and uses Irfanview as capture tool.\\
 +<code batch>
 +: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</code>
 +==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. \\
 +<code batch>
 +echo off
 +:start
 +if exist picture.png goto start
 +commandcam.exe /quiet /filename picture.bmp /delay 10
 +bmp2png.exe -Q picture.bmp 
 +goto start
 +</code>
 +>**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:
 +<code>
 +commandcam.exe /devlistdetail
 +</code>
 +If multiple video devices are installed, an additional option can select the device. \\
 +In this example the device number "2":
 +<code>
 +...
 +commandcam.exe /quiet /filename picture.bmp /delay 10 /devnum 2
 +...
 +</code>
 +
 +
 +=====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...