Skip to content

Instantly share code, notes, and snippets.

View tersekmatija's full-sized avatar

Matija Teršek tersekmatija

View GitHub Profile
@tersekmatija
tersekmatija / coco-labels-91.txt
Created December 8, 2021 07:47
Labels of 91 classes in the COCO dataset
person
bicycle
car
motorbike
aeroplane
bus
train
truck
boat
trafficlight
@tersekmatija
tersekmatija / uv_coords.txt
Created October 27, 2021 10:08
UV_COORDS.txt for MediaPipe's facial landmarks model (for Medium tutorial)
4.999769926071169768e-01 6.525340080261230469e-01
5.000259876251219593e-01 5.474870204925540440e-01
4.999740123748779852e-01 6.023719906806950242e-01
4.821130037307739813e-01 4.719790220260620117e-01
5.001509785652159534e-01 5.271559953689579636e-01
4.999099969863889936e-01 4.982529878616330232e-01
4.995230138301849920e-01 4.010620117187500000e-01
2.897120118141169876e-01 3.807640075683589864e-01
4.999549984931950242e-01 3.123980164527889736e-01
4.999870061874390204e-01 2.699189782142640270e-01
@tersekmatija
tersekmatija / render_effect.py
Created October 27, 2021 09:46
Rendering with Delaunay triangulation using OpenCV (for Medium tutorial)
# empty overlay image to which we render the effect
overlay = np.zeros((192, 192, 4), np.uint8)
# loop through all triangles computed with Delaunay triangulation
for idx_tri in triangles:
# Step 1 - get corresponding triangles from source and target image
idx_tri = idx_tri.astype(int)
src_tri = src_points[idx_tri]
dst_tri_full = dst_points[idx_tri]
@tersekmatija
tersekmatija / add_overlay.py
Created October 27, 2021 09:40
Add transparent image to the background image with OpenCV (for Medium tutorial)
# compute alpha masks
a = overlay[:, :, 3]
# we can also add some blur
# a = cv2.medianBlur(a,1)
b = 255 - a
# sum
overlay[:,:,:3] * np.dstack([a/255]*3) + frame[:,:,:3] * np.dstack([b/255]*3)
@tersekmatija
tersekmatija / delaunay_triangulation.py
Last active October 27, 2021 09:38
Example of Delaunay triangulation with OpenCV on Facial landmarks (for Medium tutorial)
subdiv = cv2.Subdiv2D((0, 0, 192, 192))
subdiv.insert(list(ldms[:, :2]))
for triangle in subdiv.getTriangleList():
triangle_pts = np.array(triangle.reshape((3,2)).astype(np.int32).tolist())
cv2.drawContours(frame, [triangle_pts], 0, (0,255,0), 1)