public void TestData() { Byte[,] data = new Byte[20, 30]; Random r = new Random(); Byte[] bytes = new Byte[data.Length]; r.NextBytes(bytes); for (int i = 0; i < data.GetLength(0); i++) { for (int j = 0; j < data.GetLength(1); j++) { data[i, j] = bytes[i * data.GetLength(1) + j]; } } Matrix <Byte> m = new Matrix <byte>(data); Byte[,] data2 = m.Data; for (int i = 0; i < data.GetLength(0); i++) { for (int j = 0; j < data.GetLength(1); j++) { EmguAssert.AreEqual(data[i, j], data2[i, j]); EmguAssert.AreEqual(data[i, j], m[i, j]); } } }
public void TestQuaternionsSize() { #if NETFX_CORE EmguAssert.AreEqual(4 * Marshal.SizeOf <double>(), Marshal.SizeOf <Quaternions>()); #else EmguAssert.AreEqual(4 * Marshal.SizeOf(typeof(double)), Marshal.SizeOf(typeof(Quaternions))); #endif }
public void TestSparseMatrix() { int[] dimension = new int[2]; dimension[0] = 1000000; dimension[1] = 1000000; //without sparase matrix, a matrix of this size is almost impossible to create in memory using (SparseMatrix <double> m1 = new SparseMatrix <double>(dimension)) { m1[3, 10009] = 2.0; EmguAssert.AreEqual(2.0, m1[3, 10009]); } }
public void TestMultiChannelMatrix() { Matrix <float> m = new Matrix <float>(10, 20, 2); m.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255)); EmguAssert.AreEqual(10, m.Rows); EmguAssert.AreEqual(20, m.Cols); EmguAssert.AreEqual(2, m.NumberOfChannels); XDocument xDoc = Toolbox.XmlSerialize <Matrix <float> >(m); Matrix <float> m2 = Toolbox.XmlDeserialize <Matrix <float> >(xDoc); EmguAssert.IsTrue(m.Equals(m2)); }
public void TestMatchTemplate() { if (!CudaInvoke.HasCuda) { return; } #region prepare synthetic image for testing int templWidth = 50; int templHeight = 50; Point templCenter = new Point(120, 100); //Create a random object Image <Bgr, Byte> randomObj = new Image <Bgr, byte>(templWidth, templHeight); randomObj.SetRandUniform(new MCvScalar(), new MCvScalar(255, 255, 255)); //Draw the object in image1 center at templCenter; Image <Bgr, Byte> img = new Image <Bgr, byte>(300, 200); Rectangle objectLocation = new Rectangle(templCenter.X - (templWidth >> 1), templCenter.Y - (templHeight >> 1), templWidth, templHeight); img.ROI = objectLocation; randomObj.Copy(img, null); img.ROI = Rectangle.Empty; #endregion Image <Gray, Single> match = img.MatchTemplate(randomObj, Emgu.CV.CvEnum.TemplateMatchingType.Sqdiff); double[] minVal, maxVal; Point[] minLoc, maxLoc; match.MinMax(out minVal, out maxVal, out minLoc, out maxLoc); double gpuMinVal = 0, gpuMaxVal = 0; Point gpuMinLoc = Point.Empty, gpuMaxLoc = Point.Empty; GpuMat cudaImage = new GpuMat(img); GpuMat gpuRandomObj = new GpuMat(randomObj); GpuMat gpuMatch = new GpuMat(); using (CudaTemplateMatching buffer = new CudaTemplateMatching(DepthType.Cv8U, 3, CvEnum.TemplateMatchingType.Sqdiff)) using (Stream stream = new Stream()) { buffer.Match(cudaImage, gpuRandomObj, gpuMatch, stream); //GpuInvoke.MatchTemplate(CudaImage, gpuRandomObj, gpuMatch, CvEnum.TM_TYPE.CV_TM_SQDIFF, buffer, stream); stream.WaitForCompletion(); CudaInvoke.MinMaxLoc(gpuMatch, ref gpuMinVal, ref gpuMaxVal, ref gpuMinLoc, ref gpuMaxLoc, null); } EmguAssert.AreEqual(minLoc[0].X, templCenter.X - templWidth / 2); EmguAssert.AreEqual(minLoc[0].Y, templCenter.Y - templHeight / 2); EmguAssert.IsTrue(minLoc[0].Equals(gpuMinLoc)); EmguAssert.IsTrue(maxLoc[0].Equals(gpuMaxLoc)); }
public void TestSolve() { Matrix <Single> lhs = new Matrix <Single>(3, 3); lhs.SetIdentity(); Matrix <Single> rhs = new Matrix <Single>(new float[, ] { { 0.1f }, { 0.2f }, { 0.5f } }); Matrix <Single> result = new Matrix <float>(3, 1); CvInvoke.Solve(lhs, rhs, result, CvEnum.DecompMethod.LU); EmguAssert.AreEqual(rhs[0, 0], result[0, 0]); EmguAssert.AreEqual(rhs[1, 0], result[1, 0]); EmguAssert.AreEqual(rhs[2, 0], result[2, 0]); }
public void TestTransposeFloatMatrix() { using (Matrix <float> mat = new Matrix <float>(1, 3)) { mat.SetRandUniform(new MCvScalar(-1000.0), new MCvScalar(1000.0)); Matrix <float> matT = mat.Transpose(); for (int i = 0; i < matT.Rows; i++) { for (int j = 0; j < matT.Cols; j++) { EmguAssert.AreEqual(matT[i, j], mat[j, i]); } } } }
public void TestTransposeByteMatrix() { using (Matrix <Byte> mat = new Matrix <Byte>(1, 10)) { mat.SetRandUniform(new MCvScalar(0.0), new MCvScalar(255.0)); Matrix <Byte> matT = mat.Transpose(); for (int i = 0; i < matT.Rows; i++) { for (int j = 0; j < matT.Cols; j++) { EmguAssert.AreEqual(matT[i, j], mat[j, i]); } } } }
public void TestOCRBgrText() { using (Tesseract ocr = GetTesseract()) using (Image <Bgr, Byte> img = new Image <Bgr, byte>(480, 200)) { ocr.SetVariable("tessedit_char_whitelist", "ABCDEFGHJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz,"); String message = "Hello, World"; CvInvoke.PutText(img, message, new Point(50, 100), CvEnum.FontFace.HersheySimplex, 1.0, new MCvScalar(0, 0, 255)); //ImageViewer.Show(img); ocr.Recognize(img); String messageOcr = ocr.GetText().TrimEnd('\n', '\r'); // remove end of line from ocr-ed text EmguAssert.AreEqual(message, messageOcr, String.Format("'{0}' is not equal to '{1}'", message, messageOcr)); Tesseract.Character[] results = ocr.GetCharacters(); } }
public void TestSubMatrix() { Matrix <float> mat = new Matrix <float>(30, 40); mat.SetRandUniform(new MCvScalar(0), new MCvScalar(255)); Matrix <float> submat = mat.GetSubRect(new Rectangle(5, 5, 15, 15)); for (int i = 0; i < 15; i++) { for (int j = 0; j < 15; j++) { EmguAssert.AreEqual(mat[i + 5, j + 5], submat[i, j]); } } Matrix <float> secondRow = mat.GetRow(1); for (int i = 0; i < mat.Cols; i++) { EmguAssert.AreEqual(mat[1, i], secondRow[0, i]); } Matrix <float> thirdCol = mat.GetCol(2); for (int i = 0; i < mat.Rows; i++) { EmguAssert.AreEqual(mat[i, 2], thirdCol[i, 0]); } Matrix <float> diagonal = mat.GetDiag(); for (int i = 0; i < Math.Min(mat.Rows, mat.Cols); i++) { EmguAssert.AreEqual(diagonal[i, 0], mat[i, i]); } }
public void TestQuaternionsSize() { EmguAssert.AreEqual(4 * Marshal.SizeOf(typeof(double)), Marshal.SizeOf(typeof(Quaternions))); }