Skip to content

Instantly share code, notes, and snippets.

View ibaiGorordo's full-sized avatar

Ibai Gorordo ibaiGorordo

View GitHub Profile
#!/usr/bin/env python3
import cv2
import numpy as np
import depthai as dai
from datetime import timedelta
def getMesh(calibData, camSocket, ispSize):
M1 = np.array(calibData.getCameraIntrinsics(camSocket, ispSize[0], ispSize[1]))
#!/usr/bin/env python3
import cv2
import numpy as np
import depthai as dai
from datetime import timedelta
def getMesh(calibData, camSocket, ispSize):
M1 = np.array(calibData.getCameraIntrinsics(camSocket, ispSize[0], ispSize[1]))
@ibaiGorordo
ibaiGorordo / depthai_stereo_from_host_images.py
Last active August 5, 2022 04:04
Perform stereo depth estimation using the depthai API on images from the host computer in Python.
import depthai as dai
import cv2
import numpy as np
from imread_from_url import imread_from_url
def add_host_depth(pipeline):
monoLeftNode = pipeline.create(dai.node.XLinkIn)
monoRightNode = pipeline.create(dai.node.XLinkIn)
@ibaiGorordo
ibaiGorordo / depthai-android.Dockerfile
Last active July 7, 2022 12:15
Dockerfile for building the depthai-core library for Android
#
# Run in the terminal
# - Build:
# ```
# docker build . -t depthai-builder -f depthai-android.Dockerfile
# ```
# - Create and Copy the prebuilt libraries into the host computer
# ```
@ibaiGorordo
ibaiGorordo / replace_onnx_input.py
Last active April 3, 2022 02:43
Python script for replacing a combined input into two inputs and adding a concatenate node at the beginning using ONNX graph surgeon
import onnx_graphsurgeon as gs
import numpy as np
import onnx
@gs.Graph.register()
def replace_input(self, new_inputs, old_input_name):
tensors = self.tensors()
# Create concat node to combine the new inputs
@ibaiGorordo
ibaiGorordo / onnx_create_concat.py
Created April 2, 2022 07:38
Python script for creating a model that concatenates two inputs along the channel axis using ONNX graph surgeon
import onnx_graphsurgeon as gs
import numpy as np
import onnx
left_rect_img = gs.Variable(name="left_rect", dtype=np.float32, shape=(1, 3, 240, 320))
right_rect_img = gs.Variable(name="right_rect", dtype=np.float32, shape=(1, 3, 240, 320))
concat_img = gs.Variable(name="concat_img", dtype=np.float32, shape=(1, 6, 240, 320))
concat_node = gs.Node(op="Concat", attrs={"axis": 1}, inputs=[left_rect_img, right_rect_img], outputs=[concat_img])
graph = gs.Graph(nodes=[concat_node], inputs=[left_rect_img, right_rect_img], outputs=[concat_img])
@ibaiGorordo
ibaiGorordo / split_onnx_model.py
Created April 2, 2022 02:29
Python script for splitting an ONNX model (HITNET Sceneflow in this case) into two parts
import onnx
import numpy as np
import onnx_graphsurgeon as gs
def split_model(onnx_model, input_names, output_names):
graph = gs.import_onnx(onnx_model)
tensors = graph.tensors()
graph.inputs = [tensors[input_name] for input_name in input_names]
graph.outputs = [tensors[output_name] for output_name in output_names]
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="
@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)",
@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()",