本文整理汇总了C#中Matrix.Mul方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Mul方法的具体用法?C# Matrix.Mul怎么用?C# Matrix.Mul使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.Mul方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Mul
/// <summary>
/// Multiplies the <paramref name="left" /> vector by the <paramref name="right" /> matrix.
/// </summary>
/// <param name="left">The left vector.</param>
/// <param name="right">The right matrix.</param>
/// <param name="parameters">An object that contains all parameters and functions for expressions.</param>
/// <returns>
/// The product of matrices.
/// </returns>
/// <exception cref="System.ArgumentException">The size of matrices is invalid.</exception>
public static Matrix Mul(this Vector left, Matrix right, ExpressionParameters parameters)
{
var matrix = new Matrix(new[] { left });
return matrix.Mul(right, parameters);
}
示例2: projectPoint
private Point projectPoint(Point srcPnt, Matrix<double> hMat)
{
Matrix<double> srcPntMat = new Matrix<double>(3, 1);
srcPntMat[0, 0] = srcPnt.X;
srcPntMat[1, 0] = srcPnt.Y;
srcPntMat[2, 0] = 1;
Matrix<double> dstProjMat = hMat.Mul(srcPntMat);
int dstProjX = (int)(dstProjMat[0, 0] / dstProjMat[2, 0]);
int dstProjY = (int)(dstProjMat[1, 0] / dstProjMat[2, 0]);
Point dstPnt = new Point(dstProjX, dstProjY);
return dstPnt;
}
示例3: buttonImageStitch_Click
/// <summary>
/// Main process of Image Stitching
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonImageStitch_Click(object sender, EventArgs e)
{
Point topLeft, topRight, bottomLeft, bottomRight;
var dstId = 0;
Image<Bgr, byte> currResultImg = imgStitchList[dstId];
Matrix<double> homograph = new Matrix<double>(3, 3);
homograph[0, 0] = homograph[1, 1] = homograph[2, 2] = 1;
//Image<Bgr, byte> imgResult;
for (var srcId = 1; srcId < imgStitchList.Count; ++srcId)
{
homograph = homograph.Mul(hMatList[srcId - 1]);
topLeft = projectPoint(new Point(0, 0), homograph);
topRight = projectPoint(new Point(imgStitchList[srcId].Width - 1, 0), homograph);
bottomLeft = projectPoint(new Point(0, imgStitchList[srcId].Height - 1), homograph);
bottomRight = projectPoint(new Point(imgStitchList[srcId].Width - 1, imgStitchList[srcId].Height - 1), homograph);
Console.WriteLine(String.Format("{0}, {1}\n{2}, {3}\n{4}, {5}\n{6}, {7}\n",
topLeft.X, topLeft.Y, topRight.X, topRight.Y, bottomLeft.X, bottomLeft.Y, bottomRight.X, bottomRight.Y));
// Find biggest size for the new img
Image<Bgr, byte> newImg;
newImg = imgStitchList[srcId].WarpPerspective(homograph, Math.Max(topRight.X, bottomRight.X),
Math.Max(currResultImg.Height, Math.Max(bottomLeft.Y, bottomRight.Y)), Emgu.CV.CvEnum.INTER.CV_INTER_NN,
Emgu.CV.CvEnum.WARP.CV_WARP_FILL_OUTLIERS, new Bgr(0, 0, 0));
System.Threading.Tasks.Parallel.For(0, newImg.Height, (r) =>
//for (var r = 0; r < newImg.Height; ++r)
{
// Weight of left image(dstImg)
double alpha;
int start = -1, end = currResultImg.Width - 1;
int pixel;
for (var c = 0; c < newImg.Width; ++c)
{
if (r < currResultImg.Height && c < currResultImg.Width)
{
// Mixed area
if (newImg.Data[r, c, 0] != 0 || newImg.Data[r, c, 1] != 0 || newImg.Data[r, c, 2] != 0)
{
// Start of the mixed area
if (start < 0)
start = c;
alpha = 1 - (c - start) / (double)(end - start);
for (var k = 0; k < 3; ++k)
{
pixel = (int)(currResultImg.Data[r, c, k] * alpha + newImg.Data[r, c, k] * (1 - alpha));
if (pixel < 0)
pixel = 0;
else if (pixel > 255)
pixel = 255;
newImg.Data[r, c, k] = (byte)pixel;
}
}
else
{
newImg[r, c] = currResultImg[r, c];
}
}
}
});
currResultImg = newImg.Copy();
}
pictureBoxImgStitch.Image = currResultImg.ToBitmap();
}
示例4: MulMatrices3
public void MulMatrices3()
{
var left = new Matrix(new[]
{
new Vector(new[] { new Number(-2), new Number(1) }),
new Vector(new[] { new Number(5), new Number(4) })
});
var right = new Matrix(new[]
{
new Vector(new[] { new Number(3) }),
new Vector(new[] { new Number(-1) })
});
var expected = new Matrix(new[]
{
new Vector(new[] { new Number(-7) }),
new Vector(new[] { new Number(11) })
});
var result = right.Mul(left);
}
示例5: Calibrate
public PointF Calibrate(float image_x, float image_y)
{
// If not enough mapping points are giving, don't do the calibration
if (worldPoints_list.Count < 4)
return new PointF(0, 0);
try
{
intrinsic = new IntrinsicCameraParameters();
}
catch (Exception e) { MessageBox.Show(e.InnerException.Message); }
worldPoints[0] = new MCvPoint3D32f[] { (worldPoints_list[0])[0], (worldPoints_list[1])[0], (worldPoints_list[2])[0], (worldPoints_list[3])[0] };
imagePoints[0] = new PointF[] { (imagePoints_list[0])[0], (imagePoints_list[1])[0], (imagePoints_list[2])[0], (imagePoints_list[3])[0] };
CameraCalibration.CalibrateCamera(worldPoints, imagePoints, frame_size, intrinsic, CALIB_TYPE.DEFAULT, out extrinsic);
Matrix<double> extrinsicMatrix = extrinsic[0].ExtrinsicMatrix;
// Build the H matrix out of the extrinsic pramater Matrix.
// we dont use the 3rd colunm, since we assume that world_z=0 (multiplying by world_z=0 would result to 0 anyways)
Matrix<double> H = new Matrix<double>(3, 3);
H[0, 0] = extrinsicMatrix[0, 0]; H[0, 1] = extrinsicMatrix[0, 1]; H[0, 2] = extrinsicMatrix[0, 3];
H[1, 0] = extrinsicMatrix[1, 0]; H[1, 1] = extrinsicMatrix[1, 1]; H[1, 2] = extrinsicMatrix[1, 3];
H[2, 0] = extrinsicMatrix[2, 0]; H[2, 1] = extrinsicMatrix[2, 1]; H[2, 2] = extrinsicMatrix[2, 3];
Matrix<double> H_inverse = new Matrix<double>(3, 3);
CvInvoke.cvInvert(H, H_inverse, SOLVE_METHOD.CV_LU);
// intrinsic parameters include focal length, offset, etc
Matrix<double> intrinsicMatrix_inverse = new Matrix<double>(3, 3);
CvInvoke.cvInvert(intrinsic.IntrinsicMatrix, intrinsicMatrix_inverse, SOLVE_METHOD.CV_LU);
Matrix<double> HI = new Matrix<double>(3, 3);
HI = H_inverse.Mul(intrinsicMatrix_inverse);
// This is the image_point we want to transform to world 3D coordinates
// we use the Homogeneous coordinate system, which allows us to use Matrix multiplications
// needed for translation. We also use z=1 because we assume that the camera image plane
// is at z=1. We will fix this later with the intrinsic parameter matrix (inverse) multiplication
Matrix<double> arbitraryPointMatrix = new Matrix<double>(3, 1);
arbitraryPointMatrix[0, 0] = image_x;
arbitraryPointMatrix[1, 0] = image_y;
arbitraryPointMatrix[2, 0] = 1;
// Do the projective transformation
Matrix<double> result3DMatrix = new Matrix<double>(3, 1);
result3DMatrix = (HI).Mul(arbitraryPointMatrix);
// Get the point in Homogeneous coordinate system with z=1 by dividing with z = result3DMatrix[2, 0]
// (z=1, because the image plane is at z=1)
PointF point3D = new PointF();
point3D.X = (float)(result3DMatrix[0, 0] / result3DMatrix[2, 0]);
point3D.Y = (float)(result3DMatrix[1, 0] / result3DMatrix[2, 0]);
return point3D;
}
示例6: MulMatrices2
public void MulMatrices2()
{
var left = new Matrix(new[]
{
new Vector(new[] { new Number(5), new Number(8), new Number(-4) }),
new Vector(new[] { new Number(6), new Number(9), new Number(-5) }),
new Vector(new[] { new Number(4), new Number(7), new Number(-3) })
});
var right = new Matrix(new[]
{
new Vector(new[] { new Number(3), new Number(2), new Number(5) }),
new Vector(new[] { new Number(4), new Number(-1), new Number(3) }),
new Vector(new[] { new Number(9), new Number(6), new Number(5) })
});
var expected = new Matrix(new[]
{
new Vector(new[] { new Number(11), new Number(-22), new Number(29) }),
new Vector(new[] { new Number(9), new Number(-27), new Number(32) }),
new Vector(new[] { new Number(13), new Number(-17), new Number(26) })
});
var result = left.Mul(right);
Assert.AreEqual(expected, result);
}
示例7: MulMatrices1
public void MulMatrices1()
{
var left = new Matrix(new[]
{
new Vector(new[] { new Number(-2), new Number(1) }),
new Vector(new[] { new Number(5), new Number(4) })
});
var right = new Matrix(new[]
{
new Vector(new[] { new Number(3) }),
new Vector(new[] { new Number(-1) })
});
var expected = new Matrix(new[]
{
new Vector(new[] { new Number(-7) }),
new Vector(new[] { new Number(11) })
});
var result = left.Mul(right);
Assert.AreEqual(expected, result);
}
示例8: MulByNumberMatrixTest
public void MulByNumberMatrixTest()
{
var vector1 = new Vector(new[] { new Number(2), new Number(3) });
var vector2 = new Vector(new[] { new Number(9), new Number(5) });
var matrix = new Matrix(new[] { vector1, vector2 });
var number = new Number(5);
var expected = new Matrix(new[]
{
new Vector(new[] { new Number(10), new Number(15) }),
new Vector(new[] { new Number(45), new Number(25) })
});
var result = matrix.Mul(number);
Assert.AreEqual(expected, result);
}
示例9: MatrixMulVectorTest
public void MatrixMulVectorTest()
{
var vector = new Vector(new[] { new Number(-2), new Number(1) });
var matrix = new Matrix(new[]
{
new Vector(new[] { new Number(3) }),
new Vector(new[] { new Number(-1) })
});
var expected = new Matrix(new[]
{
new Vector(new[] { new Number(-6), new Number(3) }),
new Vector(new[] { new Number(2), new Number(-1) })
});
var result = matrix.Mul(vector);
Assert.AreEqual(expected, result);
}
示例10: MulMatrices3
public void MulMatrices3()
{
var left = new Matrix(new[]
{
new Vector(new[] { new Number(-2), new Number(1) }),
new Vector(new[] { new Number(5), new Number(4) })
});
var right = new Matrix(new[]
{
new Vector(new[] { new Number(3) }),
new Vector(new[] { new Number(-1) })
});
Assert.Throws<ArgumentException>(() => right.Mul(left));
}