Video surveillance automation

Introduction

Hi all! I work not in an IT company as a system administrator. Responsibilities include the administration of CCTV systems. [мы используем CTV и HiWatch]this is a common situation, the administrator should be able to do everything at once.

I want to share the information in this article in view of the fact that it took a lot of time to find a solution to the problem and write a small script. If anyone has suggestions for a different implementation of tasks, I will be glad to read.

Task

  1. Organize the output of video surveillance from different points of the object to the monitor at the headquarters, for constant monitoring of what is happening. (Construction company, each object has a headquarters for engineering staff.)

  2. Organize a video wall in the office to control work at the facilities.

Connection of objects

In this article I will not consider ways to provide a connection with objects, we have raised VPN on firewall zyxel, there is another way – to forward ports, but you will need white IPs on all objects, which is very expensive and setting up a firewall for access from certain addresses. Therefore, I recommend setting up a VPN on the network with many manuals.

Part 1. Preparation

There are several ways to display the image from the DVRs:

  1. through smartphone applications;

  2. Direct video cable (HDMI, VGA)

  3. software for PC;

  4. Browser. (web face)

We will consider 4 option.

The question remains how to organize autologin and other manipulations in the browser, so as not to give all employees a password, and not to strain with unnecessary work, turn on the PC and everything works.

At the time of the task, I had basic knowledge of Python, I taught C ++ a long time ago at the university. The choice fell on Python, since the systems from which the whole history opens on Windows, C ++ is more complicated in syntax and has not worked with it for a long time, I did not even consider the implementation on it.

Python has a Selenium library that allows you to work with browsers, unfortunately the Web faces of our registrars work correctly only in IE… And Selenium will need a Web driver, you can download it from the library website.

Link to webdriver

Part 2. Writing

For ease of development, I used VS Code. (I will not consider installation and configuration, there is a lot of information on the network)

  1. Create a development environment, for this, in the PS shell, enter:

python -m venv hiwatch
cd hiwatch\Scripts
.\activate.ps1

We create an environment, go to the Scripts folder and activate it.

  1. Create a file .py and install Selenium.

cd .. #переходим в каталог выше hiwatch\
touch video.py #создаем файл питона
pip3 install selenium #устанавливаем Selenium

also download the file IE webdriver from the selenium website (link above) and drop it into the folder hi-watch.

  1. Below will be provided the code from the video.py file with an explanation for Hiwatch & Hikvision recorders.

#video.py

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

time.sleep(60) #здесь и далее приостановка выполнения в секундах

drive = webdriver.Ie(executable_path = r'IEDriverServer.exe') #присваиваем переменной drive исполняемый файл webdriver-a

drive.get('http://192.168.*.*/') #IP адрес регистратора может быть указан номер порта

time.sleep(15)

drive.find_element(By.ID, 'username').send_keys('log') #Ваш логин к регистратору
drive.find_element(By.ID, 'password').send_keys("pass") #Ваш пароль к регистратору
drive.find_element(By.ID, 'password').send_keys(Keys.ENTER) #Иммитация нажатия Enter для перехода на следущую страницу

time.sleep(10)

search = drive.find_element(By.CLASS_NAME, 'icon-playall') #выбор кнопки воспроизведения изображения
drive.execute_script("arguments[0].click();", search) #иммитация нажатия

time.sleep(5)

full = drive.find_element(By.CLASS_NAME, 'icon-full') #выбор кнопки изображения на полный экран
drive.execute_script("arguments[0].click();", full) #иммитация нажатия

drive.close
drive.quit
  1. Below is the code from the video.py file for the CTV recorder.

import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By

time.sleep(5) #здесь и далее приостановка выполнения в секундах

drive = webdriver.Ie(executable_path = r'IEDriverServer.exe') #присваиваем переменной drive исполняемый файл webdriver-a

drive.get('http://192.168.*.*/') #IP адрес регистратора может быть указан номер порта

time.sleep(10) 

drive.find_element(By.ID, 'txtUserName').send_keys('login')  #Ваш логин к регистратору
drive.find_element(By.ID, 'txtPassword').send_keys('Pass') #Пароль к регистратору
drive.find_element(By.ID, 'txtPassword').send_keys(Keys.ENTER) #Иммитация нажатия Enter для перехода на следущую страницу

time.sleep(10)

search1 = drive.find_element(By.ID, 'seg_selector') #открытие вкладки для выбора сетки отображения
drive.execute_script("arguments[0].click();", search1) #иммитация нажатия
search2 = drive.find_element(By.ID, 'seg_9') #выбор сетки 3*3
drive.execute_script("arguments[0].click();", search2) #иммитация нажатия

time.sleep(5)

full = drive.find_element(By.ID, 'full_screen') #выбор кнопки изображения на полный экран
drive.execute_script("arguments[0].click();", full) #иммитация нажатия

drive.close 
drive.quit 
  1. Transferring the program from .PY V .EXE to run on different hosts without installing Python and other things, we get an independent program.

pyinstaller --noconfirm --onedir --console --add-data "C:/Users/!Ваш путь к этой папке!/IEDriverServer.exe;." "C:/Users/!Ваш путь к этой папке!/video.py"
  1. The assembly is contained in the dist folder, which is located in the same directory as the hiwatch folder.

Link to my git with ready-made projects, you should specify some data in the .py file and overtake it in .EXE

Part 3. Conclusion

You just have to transfer the result from the folder dist for any car.

In conclusion, I would like to say that I am not a developer, and I could not quite correctly describe some of the actions – please do not judge strictly.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *