Skip to content

Instantly share code, notes, and snippets.

View andijakl's full-sized avatar

Andreas Jakl andijakl

View GitHub Profile
@andijakl
andijakl / keyframe_matching_visualize.py
Created November 23, 2020 15:36
Visualize matched keypoints
# Draw the keypoint matches between both pictures
# Still based on: https://docs.opencv.org/master/dc/dc3/tutorial_py_matcher.html
draw_params = dict(matchColor=(0, 255, 0),
singlePointColor=(255, 0, 0),
matchesMask=matchesMask[300:500],
flags=cv.DrawMatchesFlags_DEFAULT)
keypoint_matches = cv.drawMatchesKnn(
img1, kp1, img2, kp2, matches[300:500], None, **draw_params)
cv.imshow("Keypoint matches", keypoint_matches)
@andijakl
andijakl / keyframe_matching.py
Created November 23, 2020 15:26
Match keyframes and keep the good matches
# Match keypoints in both images
# Based on: https://docs.opencv.org/master/dc/dc3/tutorial_py_matcher.html
FLANN_INDEX_KDTREE = 1
index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
search_params = dict(checks=50) # or pass empty dictionary
flann = cv.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(des1, des2, k=2)
# Keep good matches: calculate distinctive image features
# Lowe, D.G. Distinctive Image Features from Scale-Invariant Keypoints. International Journal of Computer Vision 60, 91–110 (2004). https://doi.org/10.1023/B:VISI.0000029664.99615.94
@andijakl
andijakl / visualize_keypoints.py
Created November 23, 2020 14:49
Visualize Keypoints
# Visualize keypoints
imgSift = cv.drawKeypoints(
img1, kp1, None, flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
cv.imshow("SIFT Keypoints", imgSift)
@andijakl
andijakl / sift_keypoints.py
Created November 23, 2020 13:37
Python OpenCV implementation to calculate keypoints and their descriptors with SIFT
# 1. Detect keypoints and their descriptors
# Based on: https://docs.opencv.org/master/dc/dc3/tutorial_py_matcher.html
# Initiate SIFT detector
sift = cv.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1, None)
kp2, des2 = sift.detectAndCompute(img2, None)
@andijakl
andijakl / rectification.py
Created November 23, 2020 12:15
Part 1: load and draw the original images for stereo rectification
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
# Read both images and convert to grayscale
img1 = cv.imread('left_img.png', cv.IMREAD_GRAYSCALE)
img2 = cv.imread('right_img.png', cv.IMREAD_GRAYSCALE)
# ------------------------------------------------------------
# PREPROCESSING
@andijakl
andijakl / EnvironmentalLight.cs
Created June 4, 2020 20:02
Snippet of the EnvironmentalLight code of Google ARCore for Unity
LightEstimate estimate = Frame.LightEstimate;
// Updates directional light
DirectionalLight.transform.rotation = estimate.DirectionalLightRotation;
DirectionalLight.color = estimate.DirectionalLightColor;
// Set ambient probe
RenderSettings.ambientMode = AmbientMode.Skybox;
RenderSettings.ambientProbe = estimate.AmbientProbe;
// Set reflection probe (if activated)
RenderSettings.defaultReflectionMode = DefaultReflectionMode.Custom;
RenderSettings.customReflection = estimate.ReflectionProbe;
@andijakl
andijakl / AnchorPositioning.js
Last active January 13, 2021 23:29
Complete AnchorPositioning.js script that creates an AR anchor in Amazon Sumerian, based on the upcoming scripting API.
// Import Sumerian scripts
import * as s from 'module://sumerian-common/api';
import * as si from 'module://sumerian-common/internal';
export default class AnchorPositioning extends s.Action {
static get PROPERTIES() {
return {
// Optional property to set the owner of the AR anchor
anchorEntity: {
@andijakl
andijakl / AnchorPositioning.js
Created August 8, 2019 13:47
Subscribing to the event StartPlaceMode to enable the Augmented Reality placement mode functionality.
// Listen for the world event "StartPlaceWorld". This will be sent
// by another component in the scene when the placement mode should
// be active. When that event is received, this script sets placeMode to true,
// which actually allows this script to react to touch events.
this.startPlaceWorldEvent = ctx.world.event('StartPlaceWorld');
this.startPlaceWorldEvent.listen(ctx, data => this.placeMode.set(true));
@andijakl
andijakl / AnchorPositioning.js
Last active August 8, 2019 14:48
Call-back when the AR system of the device (ARCore / ARKit) sends the anchor ID to our scene, so that we can link it to the entity.
// Anchor registration callback. Sets the anchor ID of the entity's
// ArAnchorComponent. The engine's ArSystem will automatically update
// the world position and orientation of entities with a valid anchor ID.
registerAnchorCallback(anchorId) {
if (anchorId) {
this.internalAnchorEntity.getComponent('ArAnchorComponent').anchorId = anchorId;
console.log("Registered AR anchor: " + anchorId);
this.placeMode.set(false);
this.worldPlacedEvent.emit();
console.log("Quit place mode and sent WorldPlaced event");
@andijakl
andijakl / AnchorPositioning.js
Last active August 8, 2019 14:47
Call-back from the hit test: register an AR anchor at this position through Amazon Sumerian's ArSystem.
// Hit test callback. If the hit test was successful (i.e., detected a
// point in the real world), registers an anchor with that point.
hitTestCallback(anchorTransform) {
if (anchorTransform) {
console.log("Transform from hit test: " + anchorTransform + ". Registering anchor...");
this.arSystem.registerAnchor(anchorTransform, (anchorId) => this.registerAnchorCallback(anchorId));
} else {
console.log("No transform received from hit test");
}
}