abist-co-ltd / hololens-opencv-laserpointer

Apache License 2.0
33 stars 8 forks source link
camera-intrinsics hololens-2 laserpointer-detection opencv opencv-for-unity projection

hololens-opencv-laserpointer

Laser pointer detection sample application, demonstrating a minimal setup for

Tested on HoloLens 2 and Gen 1.

Alt Laser Pointer Detection

Dependencies

Setup

After cloning, open the project in Unity and import the OpenCV for Unity asset.
Setup OpenCVForUnity: Tools > OpenCV for Unity > Set Plugin Import Settings

Note: MRTK 2.4.0 package files are already included and configured in this repository.

Usage

Build and Deployment

For HoloLens 2, configure Unity Build Settings as follows:

Unity Build Settings

Build and deploy the application to HoloLens as described on Building your application to your HoloLens 2

SampleScene Structure and Configuration

In Unity, open SampleScene and select ImageView. Its components HoloLens Camera Stream To Mat Helper and Hololens Laser Pointer Detection implement the detection of a laser pointer in the camera image.

ImageView Components

HololensLaserPointerDetection.cs detects a red laser pointer using OpenCV for Unity, determines its 3D coordinates, and displays the distance in a tooltip.

Note: To aid debugging, camera images are retrieved from the PC's webcam instead of HoloLens, when executed in the Unity editor.

HoloLens Camera Stream To Mat Helper - Options

The original version of this component is available on HoloLens With OpenCVForUnity Example

Adjust the options of HoloLens Camera Stream To Mat Helper to balance accurracy and performance.

Option Values
Requested Width 1280, 1920, etc
Requested Height 720, 1080, etc
Requested FPS 15, 30, etc

See Locatable camera for available resolutions and frame rates.

Hololens Laser Pointer Detection - Options

Option Values Explanation
Unprojection Offset (float x, float y) Calibration of 2D -> 3D unprojection of detected laser pointer. Adjust to reduce unprojection error.
Detection Area (float x, float y) Portion of the camera image used for laser pointer detection. x and y must be between 0 and 1. Smaller values increase speed but narrow the detection area.
Is Visible Image bool Enables a panel showing the real time camera image for debugging purposes in front of the user.
Show FPS bool Enables the output of frames per seconds the laser pointer detection algorithm processes.
Fast Detection bool Enables a detection algorithm favoring performance over accuracy.

Additional Customization

Depending on the environment and type of laser pointer, it may be necessary to adjust the color range for the detected laser light in HololensLaserPointerDetection.cs method FindLaserPointer

            // Acquire a mask image of reddish pixels using the inRange method. 
            // Red is separated in two areas in the HSV color space
            Scalar s_min = new Scalar(0, 30, 220);
            Scalar s_max = new Scalar(10, 240, 255);
            Core.inRange(hsvMat, s_min, s_max, maskMat1);
            s_min = new Scalar(170, 30, 220);
            s_max = new Scalar(180, 240, 255);
            Core.inRange(hsvMat, s_min, s_max, maskMat2);

See the class and sequence diagrams in the Document folder for information on the static structure and dynamic behavior of the code.

Known Issues and Limitations

This is work in progress. Known issues are listed in Issues of this repository. Please help to improve this work by reporting bugs and areas of improvement. Ideas for laser pointer detection are particulary welcome!

Currently, detection is limited to a single red laser pointer. Red and shiny objects other than laser pointers are likely to be detected as well (false positives).

Related Information

Copyright

This code is provided by the AR Team of ABIST AI Solution under Apache License Version 2.0. It is based on the following source code: