Metadata-Version: 2.1
Name: alert-lvm
Version: 1.1.0
Summary: A client library to call the LVM API with some helpful functions
Author-email: "intellicloud.ai" <xbrain_lvm@intellicloud.ai>
License: Copyright (c) 2018 The Python Packaging Authority
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://intellicloudai.com
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Requires-Dist: opencv-python
Provides-Extra: dev
Requires-Dist: black ; extra == 'dev'
Requires-Dist: bumpver ; extra == 'dev'
Requires-Dist: isort ; extra == 'dev'
Requires-Dist: pip-tools ; extra == 'dev'
Requires-Dist: pytest ; extra == 'dev'

## Installation

You can install the alert-lvm from [PyPI](https://pypi.org/project/realpython-reader/):

    pip install alert-lvm

## How to use

### Analyze image:

```python
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):

```python
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: 

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

or you can first process the content of the frames:

```python
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

```python
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.

```python
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"))
```
