publicstaticdoubleSame(Mat image1, Mat image2) { Mat resultMat = new Mat();
Cv2.Resize(image1, resultMat, new Size(image2.Cols, image2.Rows)); int row = resultMat.Rows; int col = resultMat.Cols; int sameCount = 0; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (resultMat.At<byte>(j, i) == image2.At<byte>(j, i)) { sameCount += 1; } } }
publicstatic Mat GetMat20(Mat oldMat) { Mat whiteImage = new Mat(20, 20, MatType.CV_8U, Scalar.All(255)); if (oldMat.Width <= oldMat.Height) { Mat resultMat = new Mat();
Cv2.Resize(oldMat, resultMat, new Size(oldMat.Cols * 20 / oldMat.Rows, 20)); Rect destinationRegion = new Rect((whiteImage.Width - resultMat.Width) / 2, 0, resultMat.Width, resultMat.Height);
resultMat.CopyTo(new Mat(whiteImage, destinationRegion)); } else { Mat resultMat = new Mat();
Cv2.Resize(oldMat, resultMat, new Size(20, 20 * oldMat.Rows / oldMat.Cols)); Rect destinationRegion = new Rect(0, (whiteImage.Height - resultMat.Height) / 2, resultMat.Width, resultMat.Height);