Hi,
In this post I will explain how I was able to detect ArUco Markers using Leap Motion using the new Orion API.
This is a sample of an ArUco marker:
After searching the web and this forum and ending up writing some code myself - here is how you do it.
First you need to get a version of OpenCV that support ArUco Markers detection, as I some of the users of this forum don't compile OpenCV on a daily basis here is how to compile OpenCV:
1. Download the main OpenCV repo - https://github.com/opencv/opencv
2. Download a secondary repo that includes the code that finds the markers: https://github.com/opencv/opencv_contrib
3. Open CMake GUI, create a project for OpenCV, set a CMake param named OPENCV_EXTRA_MODULES_PATH to the path of the repo from stage 2 - to a subfolder in that repo named "modules"
4. Set the CMake param "BUILD_EXAMPLES" to true.
5. Compile OpenCV, it compiled.
The next steps are more on the topic of the post:
I looked at the OpenCV project named "(sample) detect_markers" as it is a good sample of what I wanted to do.
Now I modified the Leap Motion Orion sample named "GLUTImageSample" to show the markers.
I added this function:
And called it from "OnImage":
And this have given me this result when running "GLUTImageSample" (the added thing is the "id=1" text at the marker):
Now I tried to use LeapCameraMatrix and LeapDistortionCoeffs but could not - as they are not implemented currently in the Leap Motion SDK and you will get a missing symbol error while linking.
I wanted now to find the 3D position of the corners, I found the following for the "pre-Orion" Leap Motion SDK - Calculate the Direction to an Image Feature
I translated this to Orion and modified the "GLUTImageSample" sample.
I added code to get the markers as I did in the other sample, I also a call to OnImage as in the other sample.
Before getting the 3D position I checked that I have the same amount of markers detected on both cameras, I guess what is needed here is a set of some sort to verify you get the same markers on both cameras, as in many many cases only one camera detects the markers.
Then I added code that gets the 3D position using LeapPixelToRectilinear api:
And was able to see the 4 corners of ArUco Markers (I added the text after taking the screenshot):
So that is about it, Leap Motion is not that good for Detection of ArUco Markers, I am going to try the following to improve the detection:
- Use ArUco that are more simple, not 6X6 but 4X4 as the IR image is low res.
- I am going to try to improve the image I get from the IR camera, not sure how, if I will find something I will update this post.
- I may try to add an external IR light - as the image seems dark when far from the Leap Motion sensor. I will update if I will do it.
I wanted to share the full source code of my modifications to the sample with this forum - but as the samples source code have this as the header of the file - I can't:
/******************************************************************************\
* Copyright (C) 2012-2017 Leap Motion, Inc. All rights reserved. *
* Leap Motion proprietary and confidential. Not for distribution. *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
\******************************************************************************/
Leap Motion should consider removing this header from the samples - as this makes it problematic to share code that is based on the SDK samples between Leap Motion users.
Reference:
- OpenCV - Detection of ArUco Markers https://docs.opencv.org/trunk/d5/dae/tutorial_aruco_detection.html
- Leap Motion - Calculate the Direction to an Image Feature - https://developer-archive.leapmotion.com/documentation/cpp/devguide/Leap_Images.html#calculate-the-direction-to-an-image-feature
- This is the Leap Motion blog post that started me on this topic - as they hint there this is possible - http://blog.leapmotion.com/leapuvc/