Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. # Surveillance-camera-system---python---Flask---docker-compose-
  2.  
  3. #### Freelancer contest project
  4.  
  5. ## Key features:
  6.  
  7. * python subprocessing
  8. * parallel image processing
  9. * composite image with ```openCV```
  10. * interactive image map with ```imagemapster```
  11. * ```flask socketIO``` servers generated on the fly based on ```MySQL``` database content
  12. * all the volumes are ```bind``` types, making it easy to setup before any ```docker-compose up [...]```
  13. * ```vsftpd``` FTP interface for fast archive lookups
  14. * *modus operandi* via ```DEMOMODE``` environment variable
  15.  
  16. The only registered user 'admin' (pw:'admin') can add/delete cameras, and set up the composite image that all user can see realtime.
  17.  
  18. Non admin user 'user' can not edit the composite image, but can select one for full-frame watching, and switch back and forth between the single image and composite mode.
  19.  
  20. For the demo cameras base image can be selected from the ```static/img/``` folder. If the image is larger than the camera image size defined by ```BASEWIDTH``` and ```BASEHEIGHT``` environment variables, the actual camera server scans the image at arbitrary steps from arbitrary start position and direction, with the parameters randomly set at startup.
  21.  
  22. Setting the camera image size to 256X128 or lower by ```BASEWIDTH``` and ```BASEHEIGHT```, results random coloured timestamps - for testing.
  23.  
  24. ```DEMOMODE``` environment variable can have 4 values:
  25. 1. ```DEMOMODE=0``` (or not defined) for demo mode when:
  26. * No file IO (except the reading of the demo image)
  27. * all the image data is in memory throughout the whole process
  28. * the image data is transferred by socket IO
  29. 2. ```DEMOMODE=1``` same as mode ```0```, but makes:
  30. * the Camera server instances create (touch) null image files, named as in requirements.
  31. * Cron do test output, so timestamp-named folders with the null images as in requirements.
  32. 3. ```DEMOMODE=2``` same as mode ```0```, but image data is saved from camera servers to their last location in each second, so they are accessible to Cron for archiving.
  33. 4. ```DEMOMODE=3``` for each camera a new camera module is being created, and put in subprocess for image creation and file IO or FTP accordingly, but without socket IO as real cameras are not expected to do socket IO. Separate instances of camera modules are for socket IO and file IO, as ASCII flowchart shows below.
  34. #### Miscallaneous:
  35. 1. <br>It now works like charm by entering ```docker-compose up –build``` from the root directory of my project. Prior to that the app can be tuned by the environment variables in “.env”.
  36. 2. <br>Each image is armed with bash shell, so each of them can be playing around with:
  37. <br>```docker exec -it flask_app /bin/bash```
  38. <br>```docker exec -it flask_mysql /bin/bash```
  39. <br>```docker exec -it flask_cron /bin/bash```
  40. <br>```docker exec -it flask_ftp /bin/bash```
  41. 3. <br>To use the database (e.g. with mysql-workbench) without running the application, just move the line comment from the “sandbox mode” line to the command below (from line 36 to line 37 as they are at this point in time).
  42. <br>From:
  43. <br>```#command: tail -f /dev/null # Sandbox mode```
  44. <br>```command: gunicorn --worker-class eventlet --workers 1 --bind 0.0.0.0:5000 socketioapp:app```
  45. <br>To:
  46. <br>```command: tail -f /dev/null # Sandbox mode```
  47. <br>```#command: gunicorn --worker-class eventlet --workers 1 --bind 0.0.0.0:5000 socketioapp:app```
  48. <br>Make a connection with the ```mysqlcon.py```, or use the line from that file at the condition “not INSIDEDOCKER".
  49. <br>Host=0.0.0.0, user=user, pw=pass.
  50. 4. <br>The generated and cron-arranged files can be found in ```.data/storage```.
  51. #### Flowchart of DEMOMODE=3
  52. ```
  53. <------------+
  54. <------------+ +-------------------+ +------------+ +------------+
  55. <------------+ | SIO App | | Camera 3. | | Camera 1. |
  56. <------------+ +-------------------+ +------------+ +------------+
  57. Users |-------- role1:Web Server | | role: FTP | | role: FTP |
  58. | ----------------- | +---------|--+ +---|--------+
  59. | role2:SIO Client -----+ | |
  60. +-------------------+ | | |
  61. | \ /
  62. | | |
  63. | | |
  64. | +--v------v------+
  65. +-------------------+ | | |
  66. | CamServ (central) | | | FTP Server |
  67. +-------------------+ | | |
  68. | role1:SIO Server <-----+ +--------|-------+
  69. | ----------------- | |
  70. +------ role2:SIO Client | |
  71. | +-------------------+ |
  72. | +---------v--------+
  73. | | --------------- |
  74. | +-------------------+ | --------------- |
  75. | | Camera Server 1. <----------> Phys. |
  76. | +-------------------+ | volume |
  77. |-----> role: SIO Server | | --------------- |
  78. | +-------------------+ | --------------- |
  79. | +-------------------+ +--------------^---+
  80. | | Camera Server 2. <--\ +------------+ |
  81. | +-------------------+ --- Camera 2. | |
  82. |-----> role: SIO Server | +------------+ |
  83. | +-------------------+ |role: Client| |
  84. | +-------------------+ +------------+ |
  85. | | Camera Server 3. <-------------------------+
  86. | +-------------------+
  87. |-----> role: SIO Server |
  88. | +-------------------+
  89. | +-------------------+ +------------+
  90. | | Camera Server 4. <------------ Camera 4. |
  91. | +-------------------+ +------------+
  92. +---->| role: SIO Server | |role: Client|
  93. +-------------------+ +------------+
  94. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement