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 Texture2D, Mat to Color32[], etc.).

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

 

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
  • MatToColor32Array
  • Texture2DToMat
  • Texture2DToColor32
  • Texture2DToRenderTexture
  • Color32ArrayToMat
  • Color32ArrayToTexture2D
  • Color32ArrayToByteArray
  • ByteArrayToColor32Array
  • RenderTextureToTexture2D
  • WebCamTextureToMat
  • WebCamTextureToTexture2D
  • WebCamTextureToRenderTexture

Conversions are mostly made through memory copy or similar methods and work on all supported devices. There are 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 (64-bit) – Windows (32-bit) – Android – iOS (device)

Screenshots:

 

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