Fast and easy to use asset that brings OpenCV functionality to Unity.

 

Supports following platforms:

 

Works both in editor and as a standalone.

Includes optimised functions for easy and fast conversion between common Unity and OpenCV structures (WebCamTexture to Mat, Mat to Color32[], etc.).

Uses vanilla C++ OpenCV 3.2 with C# wrapper and syntax.

Copy plugin files to Plugins folder and you are ready to go. Does not require any post-build actions.

IDisposable is implemented along with exception redirection to standard Unity errors.

 

 

Supports following OpenCV modules:

calib3d, contrib, core, features2d, flann, highgui, imgproc, legacy, ml, nonfree, objdetect, photo, superres, video and videostab.

 

Following conversions functions are included:

  • MatToTexture2D (2.1ms)
  • MatToColor32Array (8.5ms)
  • Texture2DToMat (2.3ms)
  • Texture2DToColor32 (0.2ms)
  • Texture2DToRenderTexture (1.9ms)
  • Color32ArrayToMat (1.0ms)
  • Color32ArrayToTexture2D (1.1ms)
  • Color32ArrayToByteArray (0.7ms)
  • ByteArrayToColor32Array (2.8ms)
  • RenderTextureToTexture2D (4.4ms)
  • WebCamTextureToMat (1.2ms)
  • WebCamTextureToTexture2D (1.9ms)
  • WebCamTextureToRenderTexture (2.0ms)

Average execution times next to the function name are for VGA image using 3.2GHz Pentium Dual Core CPU and will vary for each device. Conversions are mostly made through memory copy or similar methods and work on all supported devices. No iterative conversions.
RenderTextureToTexture2D conversion also allows use of OpenCV on in-game cameras – such as the line following robot example.

 

Following helper functions are included:

  • GetWebCamTexture2D – returns image from webcam as Texture2D.
  • GetWebCamMat – return image from webcam as OpenCV mat.
  • GetIntPtr – returns pointer to the structure.
  • GetStreamingAssetsPath – returns path to the file in the Streaming Assets folder. Platform independent. Useful for ImRead and similar functions that require path to the file.

 

For auto-generated documentation with more info on included functions and classes visit Auto-generated documentation.

Demo downloads:

Linux  – MacOS – Windows – Android – iOS (device)

Screenshots:

 

Asset is currently awaiting approval on the Unity Asset Store and will be available soon.