Skip to main content

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

Release files for motion-detector-g4 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for motion-detector-g4 1.2.0
File Size Uploaded
motion_detector_g4-1.2.0.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for motion-detector-g4 1.2.0
File Interpreter ABI Platform
motion_detector_g4-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / motion_detector_g4-1.2.0.tar.gz

Download URL motion_detector_g4-1.2.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c4f77acfe11fbfbda733bc60494daeb72837926e25a201047e5f4f27b5aa55c5
BLAKE2b-256 checksum
How to use checksums
5d5ed917f755401aa561fab851a63066eade85b5f245a082eab8120605982377
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release files / motion_detector_g4-1.2.0-py3-none-any.whl

Download URL motion_detector_g4-1.2.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15a5174ea137cf3c158c6981cf185f0f9b028186ec7e48a1ca1e7c1f3f43d444
BLAKE2b-256 checksum
How to use checksums
313ebd1af5b69f2ef23fb632138b9aa694adf013dec4c1ec927b23e6ad912517
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page