Skip to content

Instantly share code, notes, and snippets.

@alvonx
alvonx / FaceDetectionModule.py
Created May 5, 2021 08:09
Using mediapipe for detecting face in the video
import cv2
import time
import mediapipe as mp
class FaceDetector:
def __init__(self, minDetectionConf=0.5):
self.minDetectionConf = minDetectionConf
self.mpFaceDetection = mp.solutions.face_detection
self.mpDraw = mp.solutions.drawing_utils
self.faceDetection = self.mpFaceDetection.FaceDetection(min_detection_confidence=self.minDetectionConf)
@alvonx
alvonx / url_2_blob.js
Created July 26, 2022 03:34
Convert video URL to BLOB (to hide the video url from accessing to outside world)
async function createFile(){
let response = await fetch('<video_url>');
let data = await response.blob();
console.log(data)
var url = URL.createObjectURL(data);
document.getElementById('video-player').src = url;
let metadata = {
type: 'video/mp4'
};
let file = new File([data], "test.jpg", metadata);
@alvonx
alvonx / xml_editor.py
Created October 12, 2022 13:13
Edit xml using python
import glob
import xml.etree.ElementTree as ET
png_images = glob.glob('<folder_containing_xml>/*.xml')
saving_path = '<saving_folder_path>'
for i in png_images:
print(i)
splitted_path = i.split('/')
path = '/'.join(splitted_path[:-1])
name_ext = splitted_path[-1]
@alvonx
alvonx / colored_python_output.py
Created October 14, 2022 16:35
Print coloured output in python console
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
@alvonx
alvonx / sample.js
Created December 5, 2022 05:40
Tainted canvases may not be exported
mainVideo = container.querySelector("video");
mainVideo.crossOrigin = "anonymous";
var dataURI = canvas.toDataURL('image/jpeg');
ctx.drawImage(mainVideo, 0, 0, canvas.width, canvas.height);
@alvonx
alvonx / onvif-snapshot.py
Last active January 23, 2023 07:14
Save snapshot from ONVIF enabled camera using python
# pip install onvif-zeep
# import package
import requests
from onvif import ONVIFCamera
# create onvif camera object
cam_obj = ONVIFCamera(CAMERA_HOST, CAMERA_PORT, CAMERA_USER, CAMERA_PASS)
# create media service
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Bootstrap CSS -->
<link
href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css"
import json
import boto3
import random
from botocore.vendored import requests
def random_url(plen=10, ucfirst=True, spchar=True):
if plen >= 6 and plen % 2 != 0:
plen = plen+1
elif plen < 8:
return None, 'length too small'
import json
import boto3
def lambda_handler(event, context):
page_name = event['queryStringParameters']['page']
cover_name = event['queryStringParameters']['cover']
print(page_name)
ssm_client = boto3.client('ssm')
import json
import boto3
def lambda_handler(event, context):
page_name = event['queryStringParameters']['page']
page_start_time = event['queryStringParameters']['starttime']
print(page_name)
print(page_start_time)