本文整理汇总了C#中Mat.empty方法的典型用法代码示例。如果您正苦于以下问题:C# Mat.empty方法的具体用法?C# Mat.empty怎么用?C# Mat.empty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat.empty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
void Start()
{
//Read the left and right images
Texture2D texLeft = Resources.Load ("tsukuba_l") as Texture2D;
Texture2D texRight = Resources.Load ("tsukuba_r") as Texture2D;
Mat imgLeft = new Mat (texLeft.height, texLeft.width, CvType.CV_8UC1);
Mat imgRight = new Mat (texRight.height, texRight.width, CvType.CV_8UC1);
Utils.texture2DToMat (texLeft, imgLeft);
Utils.texture2DToMat (texRight, imgRight);
//or
//Mat imgLeft = Imgcodecs.imread (Utils.getFilePath ("tsukuba_l.png"), Imgcodecs.IMREAD_GRAYSCALE);
//Mat imgRight = Imgcodecs.imread (Utils.getFilePath ("tsukuba_r.png"), Imgcodecs.IMREAD_GRAYSCALE);
Mat imgDisparity16S = new Mat (imgLeft.rows (), imgLeft.cols (), CvType.CV_16S);
Mat imgDisparity8U = new Mat (imgLeft.rows (), imgLeft.cols (), CvType.CV_8UC1);
if (imgLeft.empty () || imgRight.empty ()) {
Debug.Log ("Error reading images ");
}
StereoBM sbm = StereoBM.create (16, 15);
sbm.compute (imgLeft, imgRight, imgDisparity16S);
//normalize to CvType.CV_8U
Core.normalize (imgDisparity16S, imgDisparity8U, 0, 255, Core.NORM_MINMAX, CvType.CV_8U);
Texture2D texture = new Texture2D (imgDisparity8U.cols (), imgDisparity8U.rows (), TextureFormat.RGBA32, false);
Utils.matToTexture2D (imgDisparity8U, texture);
gameObject.GetComponent<Renderer> ().material.mainTexture = texture;
}
示例2: calc_params
public void calc_params (Point[] pts, Mat weight, float c_factor)
{
int n = pts.Length;
// assert(V.rows == 2*n);
// Debug.Log ("V.rows == 2*n " + V.rows () + " " + 2 * n);
using (Mat s = (new MatOfPoint2f (pts)).reshape (1, 2 * n)) { //point set to vector format
if (weight.empty ()) {
Core.gemm (V.t (), s, 1, new Mat (), 0, p); //simple projection
} else { //scaled projection
if (weight.rows () != n) {
Debug.Log ("Invalid weighting matrix");
}
int K = V.cols ();
using (Mat H = Mat.zeros (K, K, CvType.CV_32F))
using (Mat g = Mat.zeros (K, 1, CvType.CV_32F)) {
for (int i = 0; i < n; i++) {
using (Mat v = new Mat (V, new OpenCVForUnity.Rect (0, 2 * i, K, 2)))
using (Mat tmpMat1 = new Mat ())
using (Mat tmpMat2 = new Mat ())
using (Mat tmpMat3 = new Mat ()) {
float w = (float)weight.get (i, 0) [0];
Core.multiply (v.t (), new Scalar (w), tmpMat1);
Core.gemm (tmpMat1, v, 1, new Mat (), 0, tmpMat2);
Core.add (H, tmpMat2, H);
Core.gemm (tmpMat1, new MatOfPoint2f (pts [i]).reshape (1, 2), 1, new Mat (), 0, tmpMat3);
Core.add (g, tmpMat3, g);
}
}
Core.solve (H, g, p, Core.DECOMP_SVD);
}
}
}
clamp (c_factor); //clamp resulting parameters
}