GithubHelp home page GithubHelp logo

motion_detector's Introduction

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

motion_detector's People

Contributors

genzo4 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.