View lazy_property.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
def lazy_property(func): | |
''' Caches the return value of a function, and turns it into a property. | |
Intended to be used as a function decorator:: | |
>>> class Foo: | |
>>> @lazy_property | |
>>> def bar(self): |
View parse_telegram_export.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' The parse_telegram_export function in this gist parses the html export of a Telegram chat. | |
You should have [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/) and | |
[dateutil](https://dateutil.readthedocs.io/) installed. It extracts the sender name, the | |
message date and time, the message text and the links in the message. | |
''' | |
from bs4 import BeautifulSoup | |
import dateutil | |
def parse_telegram_export(html_str, tz_name=None): |
View test-launch.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gi | |
gi.require_version('Gst', '1.0') | |
gi.require_version('GstRtspServer', '1.0') | |
from gi.repository import GLib, Gst, GstRtspServer | |
Gst.init(None) | |
import argparse | |
parser = argparse.ArgumentParser(description='GStreamer RTSP server test-launch') |
View backpack-annotation-example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import panoramasdk | |
from backpack.annotation import ( | |
Point, LabelAnnotation, RectAnnotation, TimestampAnnotation, | |
OpenCVImageAnnotationDriver, | |
PanoramaMediaAnnotationDriver | |
) | |
class Application(panoramasdk.node): | |
def __init__(self): |
View kvsspyglass-usage.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import panoramasdk | |
from backpack.kvs import KVSSpyGlass, KVSFileCredentialsHandler | |
# You might want to read these values from Panorama application parameters | |
stream_region = 'us-east-1' | |
stream_name = 'panorama-video' | |
# The example Dockerfile writes static configuration variables to this file | |
# If you change the .env file path in the Dockerfile, you should change it also here | |
DOTENV_PATH = '/panorama/.env' |
View local_ref.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import json | |
from pathlib import Path | |
from urllib.parse import urljoin | |
import jsonschema | |
def add_local_schemas_to(resolver, schema_folder, base_uri, schema_ext='.schema.json'): | |
''' Add local schema instances to a resolver schema cache. | |
View panorama-process-media-fix.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Application(panoramasdk.node): | |
# ... | |
def process_media(self, stream): | |
image_data, ratio = self.preprocess(stream.image, self.MODEL_INPUT_SIZE) | |
inference_results = self.call( | |
{self.MODEL_INPUT_NAME: image_data}, self.MODEL_NODE | |
) | |
self.process_results(inference_results, stream, ratio) |
View panorama-yolox-postprocess.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from yolox_postprocess import demo_postprocess, multiclass_nms | |
class Application(panoramasdk.node): | |
# ... | |
def process_results(self, inference_results, stream, ratio): | |
media_height, media_width, _ = stream.image.shape | |
media_scale = np.asarray([media_width, media_height, media_width, media_height]) | |
for output in inference_results: |
View panorama-yolox-preprocess.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
class Application(panoramasdk.node): | |
# ... | |
def preprocess(self, img, input_size, swap=(2, 0, 1)): | |
if len(img.shape) == 3: | |
padded_img = np.ones((input_size[0], input_size[1], 3), dtype=np.uint8) * 114 | |
else: |
NewerOlder