Giter Club home page Giter Club logo

hololens-opencv-laserpointer's Introduction

hololens-opencv-laserpointer

Laser pointer detection sample application, demonstrating a minimal setup for

  • HoloLens camera image processing using OpenCV for Unity
  • unprojection of camera pixels to 3D coordinates in the world space.

Tested on HoloLens 2 and Gen 1.

Alt Laser Pointer Detection

Dependencies

  • Unity 2019.4.x LTS + UWP Build Support + Visual Studio 2019
  • MRTK 2.4.0
  • OpenCV for Unity 2.3.9

Basic setup of HoloLens dev environment (Emulator is not required): Install the tools

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:

  • VulcanTechnologies HoloLensCameraStream for Unity (Apache License Version 2.0)

    • Source files from HoloLensCameraStream for Unity are included to Assets/Script/HoloLensCameraStream/ with the the following modifications:

      1. Code referring to Windows Runtime API is wrapped by
        #if ENABLE_WINMD_SUPPORT ... #endif
        to avoid compile errors in the Unity editor.
      2. Added method GetCameraIntrinsics returning the camera intrinsics object of a video media frame.
      file name modification a) modification b)
      CameraParameters.cs
      CapturePixelFormat.cs
      LocatableCameraUtils.cs
      Resolution.cs
      ResultType.cs
      VideoCapture.cs
      VideoCaptureResult.cs
      VideoCaptureSample.cs
  • EnoxSoftware HoloLens With OpenCVForUnity Example

    • Source file HololensCameraStreamToMatHelper.cs from HoloLens With OpenCVForUnity Example is included to Assets/Script/HoloLensWithOpenCVForUnityExample/ with the following modifications:
      • Retrieve CameraIntrinsics from VidoCaptureSample object and pass it to FameMatAcquiredCallback
    • The structure of HololensLaserPointerDetection.cs is inspired by HoloLensComicFilterExample.cs from HoloLens With OpenCVForUnity Example
  • Microsoft MixedRealityToolkit-Unity (MIT License)

hololens-opencv-laserpointer's People

Contributors

franzabist avatar s-sumi1103 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.