Skip to main content

Motion Detector

Project description

Language

Motion Detector

PyPI PyPI - License PyPI - Python Version

Python module for comparing two frames from a video for motion.


Installation

Package Installation from PyPi

$ pip install motion-detector-g4

Package Installation from Source Code

The source code is available on GitHub.
Download and install the package:

$ git clone https://github.com/Genzo4/motion_detector
$ cd motion_detector
$ pip install -r requirements.txt
$ pip install .

Basic usage

Import:

from motion_detector_g4 import MotionDetector

Create an instance of the motion detector. You can specify additional options:

  • min_area - minimum tracked change size (blob size). Default value: 4000.
  • max_area - maximum tracked change size (blob size). Default value: 150000.
  • noise_size - the maximum size of the removed noise. Default value: 10.
  • debug - debug mode. If it is enabled, intermediate frames are created, showing the process of processing. Default value: False.
md = MotionDetector(min_area=4000, max_area=150000, noise_size=10, debug=False)

The module uses the following algorithm:

  1. The first frame is being processed (method apply_first_frame). Img. 1
  2. The next frame is being processed (method check_motion): Img. 2
    • the first frame is subtracted from this frame using the module BackgroundSubtractorMOG2 from the library OpenCV. If debug mode is enabled, then a file is created with an additional extension "mask" with the result of the module.
      Img. 3
    • remove noise using the morphologyEx module from the OpenCV library. This process configured using the noise_size parameter. If debug mode is enabled, then a file is created with the additional extension "clear" with the result of the module's operation. Img. 4
    • looking for areas of motion (blobs) larger than min_area but smaller than max_area. If debug mode is enabled, then files are created with the extension "blobs" and "blobs2" with the result of the module's operation (found areas are circled in red). Img. 5 Img. 6

See the example.py file for an example of usage.


Language

Motion Detector

PyPI PyPI - License PyPI - Python Version

Python модуль для сравнения двух кадров из видеозаписи на предмет наличия движения в них.


Установка

Установка пакета с PyPi

$ pip install motion-detector-g4

Установка пакета из исходного кода

Исходный код размещается на GitHub.
Скачайте его и установите пакет:

$ git clone https://github.com/Genzo4/motion_detector
$ cd motion_detector
$ pip install -r requirements.txt
$ pip install .

Использование

Подключаем:

from motion_detector_g4 import MotionDetector

Создаём экземпляр детектора движения. Можно указать дополнительные параметры:

  • min_area - минимальный размер отслеживаемого изменения (размера blob'а). Значение по умолчанию: 4000.
  • max_area - максимальный размер отслеживаемого изменения (размера blob'а). Значение по умолчанию: 150000.
  • noise_size - максимальный размер удаляемого "шума". Значение по умолчанию: 10.
  • debug - режим отладки. Если его включить, то создаются промежуточные кадры, показывающие процесс обработки. Значение по умолчанию: False.
md = MotionDetector(min_area=4000, max_area=150000, noise_size=10, debug=False)

В модуле используется следующий алгоритм:

  1. Подаётся на обработку первый кадр (метод apply_first_frame). Рис. 1
  2. Подаётся на обработку следующий кадр (метод check_motion): Рис. 2
    • из этого кадра "вычитается" первый кадр с помощью модуля BackgroundSubtractorMOG2 из библиотеки OpenCV. Если включён режим отладки, то создаётся файл с добавочным расширением "mask" с результатом работы модуля.
      Рис. 3
    • удаляем "шум" с помощью модуля morphologyEx из библиотеки OpenCV. Данный процесс настраивается с помощью параметра noise_size. Если включён режим отладки, то создаётся файл с добавочным расширением "clear" с результатом работы модуля. Рис. 4
    • ищем области движения (blob'ы) размером больше min_area, но меньше max_area. Если включён режим отладки, то создаются файлы с добавочным расширением "blobs" и "blobs2" с результатом работы модуля (найденные области обводятся красными кругами). Рис. 5 Рис. 6

Пример использования см. в файле example.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

motion_detector_g4-1.2.0.tar.gz (8.4 kB view hashes)

Uploaded Source

Built Distribution

motion_detector_g4-1.2.0-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page