Catalog PyPI
PACKAGE EXPLORERView in registry

adaptive-motion-preprocessing

PyPI

Adaptive motion preprocessing: video frames in, encoded motion images out.

computer-visionmotion-detectionopencvpreprocessing
Versions collected1
Direct dependencies4From release 1.0.0
Last observed20 Oct, 19:07 UTC

README

Version 1.0.0 documentation

🎞️ Adaptive Motion Preprocessing

Turn video into motion images your neural network can read.

While something moves, each window of frames becomes one grayscale picture: older frames dim, newer ones bright, so a single image shows where the subject went and how fast. Every image has the same shape, so your model never gets a surprise.

📦 Install

pip install adaptive-motion-preprocessing

Then import amprep.

🚀 Quick start

You bring the frames (any iterable of uint8 BGR arrays) and the package does the rest:

import cv2

from amprep import AdaptiveMotionPreprocessor


def frames_from(path):
    capture = cv2.VideoCapture(path)
    try:
        if not capture.isOpened():
            raise OSError(f"cannot open video: {path}")
        while True:
            ok, frame = capture.read()
            if not ok:
                return
            yield frame
    finally:
        capture.release()


for image in AdaptiveMotionPreprocessor().process(frames_from("clip.mp4")):
    print(image.data.shape)

🎥 Try it on your webcam

See your camera and the motion images side by side, live:

git clone https://github.com/sdrfsh/adaptive-motion-preprocessing
cd adaptive-motion-preprocessing
pip install -e .
python examples/live_camera.py

Stay out of shot for a second while it learns the background, then move. Press q or Esc to quit. Add --camera 1 for an external webcam, or --threshold 0.03 if it triggers when nothing is moving.

⚙️ Settings

All optional keyword arguments of AdaptiveMotionPreprocessor(...):

SettingDefaultWhat it does
motion_threshold0.01Share of the frame that must be moving before frames are collected
window_frames10Frames per window, and one image per full window
sample_frames4Frames painted into each image (at most window_frames)
width, heightNoneOutput size; leave unset to keep the frame size, or set both
noise_reducermedian filterYour own NoiseReducer subclass
background_subtractorKNNYour own BackgroundSubtractor subclass

💡 Good to know

  • ⏱️ Frames, not seconds. 10 frames is about 0.33 s at 30 fps and 1 s at 10 fps. The package never reads the frame rate, so that math is yours.
  • 🔁 A steady stream. While motion lasts you get one image every window_frames frames. A half-full window is dropped when motion stops.
  • 🌱 Warm-up. The default subtractor spends its first 4 frames learning the background, so they never produce images. Change it with KNNBackgroundSubtractor(warmup_frames=...).
  • 🎬 New scene? Call reset(). It forgets the background, any half-built window and the frame size. Otherwise state carries over between process() calls.
  • 📐 One frame size per scene. Frames that change size mid-stream raise a ValueError. Call reset() first if the change is on purpose.

📚 Examples

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
1.0.014 Sept 20264

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
sdrfsh/adaptive-motion-preprocessing

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:07 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:1a5d164c749fb33501fadf524a1198eeec885ce4315102503a90089f6816bc63