Skip to content

Instantly share code, notes, and snippets.

View ibaiGorordo's full-sized avatar

Ibai Gorordo ibaiGorordo

View GitHub Profile
import numpy as np # numpy - manipulate the packet data returned by depthai
import cv2 # opencv - display the video stream
import depthai # access the camera and its data packets
import consts.resource_paths # load paths to depthai resources
import os
device = depthai.Device("", False)
# Create the pipeline using the 'depth_sipp' stream, establishing the first connection to the device.
pipeline = device.create_pipeline(config={
@ibaiGorordo
ibaiGorordo / face_mask_detection_examples.csv
Last active August 22, 2020 09:03
List of face mask detection model examples
Repository Author Dataset Model Input shape Platform URL
FaceMaskDetection AIZOOTech AIZOOTech (7959 images) Small CNN (SSD) 260 x 260 Multiple https://github.com/AIZOOTech/FaceMaskDetection
Face-Mask-Detection chandrikadeb7 Custom (3835 images) ResNet (SSD) (face detection) + MovileNetV2 (mask classification) 300 x 300 (face detection) + 224 x 224 (mask classification) Tensorflow + OpenCV https://github.com/chandrikadeb7/Face-Mask-Detection
face-mask-detection-tf2 PureHing Modified AIZOOTech (7959 images) Mobilenet + RFB (SSD) 240 x 240 Tensorflow 2.1 https://github.com/PureHing/face-mask-detection-tf2
Face-Mask-Detection mk-gurucharan Prajna Bhandary’s dataset (1376 images) Cascade Classifier for face detection + very small CNN for face mask classification 150 x 150 Tensorflow + OpenCV https://github.com/mk-gurucharan/Face-Mask-Detection
face_mask_detection Spidy20 Custom (using webcam) faster_rcnn_inception_v2 312 x 224 Tensorflow https://github.com/Spidy20/face_mask_de
@ibaiGorordo
ibaiGorordo / demo_mask_detector.py
Last active August 22, 2020 10:49
Demo script to run face mask inference using the OAK-D
import numpy as np
import cv2
from demo_helpers import config, capture_image, get_detection, calculate_frame_speed, decode_mobilenet_ssd, show_mobilenet_ssd
from time import time, sleep, monotonic
import os
import depthai
print('Using depthai module from: ', depthai.__file__)
# Create a list of enabled streams ()
stream_names = ['metaout', 'previewout']
@ibaiGorordo
ibaiGorordo / yolov4-tiny-darknet-mask-detection.ipynb
Created August 24, 2020 09:37
YOLOv4-tiny-Darknet-Mask-Detection.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ibaiGorordo
ibaiGorordo / MediapipModelInputCheckExample.py
Last active November 7, 2021 12:46
Python script to analyze the input image transformation of the Mediapipe face detection model.
# Referenes:
# - Resize and pad: https://stackoverflow.com/questions/44720580/resize-image-canvas-to-maintain-square-aspect-ratio-in-python-opencv
# - Mediapipe image scale and offset: https://github.com/google/mediapipe/blob/ecb5b5f44ab23ea620ef97a479407c699e424aa7/mediapipe/calculators/tensor/image_to_tensor_utils.cc#L79
# - Mediapipe OpenCV image resize: https://github.com/google/mediapipe/blob/ecb5b5f44ab23ea620ef97a479407c699e424aa7/mediapipe/framework/deps/image_resizer.h#L27
import mediapipe as mp
from mediapipe.python import solution_base
import cv2
import numpy as np
import matplotlib.pyplot as plt
@ibaiGorordo
ibaiGorordo / MediapipeModelRawOutputCheckExample.py
Created November 7, 2021 12:45
Python script to analyze the what the model inference is doing in Mediapipe.
# Referenes:
# - Mediapipe face detection models: https://github.com/google/mediapipe/tree/master/mediapipe/modules/face_detection
import os
import urllib
import mediapipe as mp
from mediapipe.python import solution_base
import cv2
import numpy as np
images = np.zeros((1, 3, 360, 640), dtype=np.float32)
masks = np.ones((1, 1, 360, 640), dtype=np.float32)
torch.onnx.export(nnet.model,
(images, masks),
"model_float32.onnx",
export_params=True,
opset_version=11,
do_constant_folding=True,
input_names = ['input_rgb','input_mask'],
@ibaiGorordo
ibaiGorordo / replace_depthai_pipeline_create.py
Created March 1, 2022 04:44
Replaces the old pipeline.create with the new create functions.
from tempfile import mkstemp
from shutil import move, copymode
from os import fdopen, remove
import os
# Ref: https://github.com/luxonis/depthai-python/blob/main/src/pipeline/PipelineBindings.cpp
pattern_replacement = { "create(dai.node.XLinkIn)" : "createXLinkIn()",
"create(dai.node.XLinkOut)" : "createXLinkOut()",
"create(dai.node.NeuralNetwork)" : "createNeuralNetwork()",
"create(dai.node.ColorCamera)" : "createColorCamera()",
@ibaiGorordo
ibaiGorordo / replace_depthai_createNode_calls.py
Created March 2, 2022 14:37
Replace the depthai pipeline.createNode() calls with create([node])
from tempfile import mkstemp
from shutil import move, copymode
from os import fdopen, remove
import os
# Ref: https://github.com/luxonis/depthai-python/blob/main/src/pipeline/PipelineBindings.cpp
pattern_replacement = { "createXLinkIn()" : "create(dai.node.XLinkIn)",
"createXLinkOut()" : "create(dai.node.XLinkOut)",
"createNeuralNetwork()" : "create(dai.node.NeuralNetwork)",
"createColorCamera()" : "create(dai.node.ColorCamera)",
from tempfile import mkstemp
from shutil import move, copymode
from os import fdopen, remove
import os
import re
def has_old_style(file_path):
pattern = "CODE="