This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Visualize keypoints | |
imgSift = cv.drawKeypoints( | |
img1, kp1, None, flags=cv.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS) | |
cv.imshow("SIFT Keypoints", imgSift) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); | |
} | |
} |