Matインスタンスを作成
Mat imgMat = new Mat (imgTexture.height, imgTexture.width, CvType.CV_8UC4);
Mat()
OpenCVForUnity.CoreModule.Mat.Mat (
int rows,
int cols,
int type
)
Parameters
rows Number of rows in a 2D array.
cols Number of columns in a 2D array.
type Array type. Use CV_8UC1,..., CV_64FC4 to create 1-4 channel matrices, or CV_8UC(n),..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
typeとは
Texture2DをMatに変換
Utils.texture2DToMat (imgTexture, imgMat);
texture2DToMat()
static void OpenCVForUnity.UnityUtils.Utils.texture2DToMat(
Texture2D texture2D,
Mat mat,
bool flip = true,
int flipCode = 0
)
Converts Unity Texture2D to OpenCV Mat.
This method converts the Unity Texture2D image to the OpenCV Mat.
The Texture object must have the read/write enabled flag set in the texture import settings, otherwise this function will fail. (GetPixels32() method is needed.)
The Mat object must have the same size as the Texture2D (width * height).
The Mat object must have the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).
Parameters
texture2D the Texture2D object must have the read/write enabled flag set in the texture import settings, otherwise this function will fail. (GetPixels32() method is needed.)
mat the Mat object must have the same size as the Texture2D (width * height). The Mat object must have the types 'CV_8UC4' (RGBA) , 'CV_8UC3' (RGB) or 'CV_8UC1' (GRAY).
flip if true, the mat is fliped after converting.
flipCode a flag to specify how to flip the array; 0 means flipping around the x-axis and positive value (for example, 1) means flipping around y-axis. Negative value (for example, -1) means flipping around both axes.
Texture2Dインスタンスを作成
Texture2D texture = new Texture2D (imgMat.cols (), imgMat.rows (), TextureFormat.RGBA32, false);
Texture2D Constructor
Texture2D(int width, int height, TextureFormat textureFormat = TextureFormat.RGBA32, bool mipChain = true, bool linear = false);
MatをTexture2Dに変換
Utils.matToTexture2D (imgMat, texture);
matToTexture2D()
static void OpenCVForUnity.UnityUtils.Utils.matToTexture2D(
Mat mat,
Texture2D texture2D,
bool flip = true,
int flipCode = 0,
bool flipAfter = false,
bool updateMipmaps = false,
bool makeNoLongerReadable = false
)