Skip to main content

A client library to call the LVM API with some helpful functions

Project description

Installation

You can install the alert-lvm from PyPI:

pip install alert-lvm

How to use

Analyze image:

from alertlvm import AlertLVM

client = AlertLVM(
    token="<your token here>"
)

scenario_key = "<the key>"

image_path = "<image_path>"

result = client.analyze(scenario_key, image_path)
if result.get("error"):
    print(result.get("code"))
    print(result.get("error_message"))
else:
    print(result.get("conclusion")) # conclusion of the analysis
    print(result.get("text")) # detail content of the analysis

    # ... your code here ...

    os.remove(result.get("frame"))

Analyze video:

The default setting is to extract and analyze one frame every 750 frames (250 frames/second * 30 seconds):

import os
from alertlvm import AlertLVM

client = AlertLVM(
    token="<your token here>"
)

scenario_key = "<the key>"

video_path = "<video_path>"

for result in client.analyzeVideo(scenario_key, video_path):
    if result.get("error"):
        print(result.get("code"))
        print(result.get("error_message"))
    else:
        print(result.get("frame")) # the file path of a frame extracted from the video that has been sent to the server
        print(result.get("conclusion")) # conclusion of the analysis
        print(result.get("text")) # detail content of the analysis

        # ... your code here ...

        os.remove(result.get("frame"))

You can also define your own frame extraction strategy, which can be based on interval:

def filter(index, frame):
    return index % 900 == 0 # every 900 frames

or you can first process the content of the frames:

def filter(index, frame):
    b = process(frame) # define a function to decide if the frame need be analyzed
    return b

and then use the filter function

import os
from alertlvm import AlertLVM

client = AlertLVM(
    token="<your token here>"
)

scenario_key = "<the key>"

video_path = "<video_path>"

for result in client.analyzeVideo(scenario_key, video_path, filter):
    if result.get("error"):
        print(result.get("code"))
        print(result.get("error_message"))
    else:
        print(result.get("frame")) # the file path of a frame extracted from the video that has been sent to the server
        print(result.get("conclusion")) # conclusion of the analysis
        print(result.get("text")) # detail content of the analysis

        # ... your code here ...

        os.remove(result.get("frame"))

Show result:

Please note that the show method will block the current thread. You can press the 'q' key or use the close button to close the current window. Only after this will the program continue to execute.

import os
from alertlvm import AlertLVM

client = AlertLVM(
    token="<your token here>"
)

scenario_key = "<the key>"

video_path = "<video_path>"

for result in client.analyzeVideo(scenario_key, video_path):
    if 'error' not in result:
        print(result.get("text")) # detail content of the analysis
        client.show(result) # show result
        os.remove(result.get("frame"))

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

alert_lvm-1.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

alert_lvm-1.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file alert_lvm-1.1.0.tar.gz.

File metadata

  • Download URL: alert_lvm-1.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for alert_lvm-1.1.0.tar.gz
Algorithm Hash digest
SHA256 4866929d48eb298676b672a98ec5d5f5ee9ed3d499a19141876ba155f901c66f
MD5 c8d0d24d7fbc05aa9af08e7b955d59d2
BLAKE2b-256 9c3f047d7042fad021fe0bfd1cde67a6278325669bf1acef7796e71369078597

See more details on using hashes here.

File details

Details for the file alert_lvm-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: alert_lvm-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for alert_lvm-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6c0f1883c59ce02b793fdb240f47f48226b7d23c61b5c9259509967ec646a0e
MD5 b9e8f194cbba63825c2a9459a48e73bb
BLAKE2b-256 3c861632b08350d9ce30913d99069beb3975212f7dfff7e98772343223f35cda

See more details on using hashes here.

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