public static void ShowPlot(double[][] trainData) { //繪製視覺化 int RectSize = 56 * 2; Mat img = new Mat(RectSize, RectSize, Emgu.CV.CvEnum.DepthType.Cv8U, 1); img.SetTo(new Emgu.CV.Structure.MCvScalar(0x0, 0x0, 0x0));//清除,不然會有雜點 for (int i = 0; i < trainData.Length; i++) { MatExtension.SetValue(img, (int)(RectSize / 4 * trainData[i][1]) + RectSize / 2, (int)(trainData[i][0] * RectSize / 7), (byte)0xFF); } CvInvoke.Flip(img, img, Emgu.CV.CvEnum.FlipType.Vertical); CvInvoke.Resize(img, img, new System.Drawing.Size(56 * 4, 56 * 4), 0, 0, Emgu.CV.CvEnum.Inter.Nearest); CvInvoke.Imshow("img", img); CvInvoke.WaitKey(1); }
public static Mat Do(Mat srcImg, bool isMax, out double[] inputVector) { //Max Pooling Mat poolingImg = new Mat(srcImg.Rows / 2, srcImg.Cols / 2, Emgu.CV.CvEnum.DepthType.Cv8U, 1); inputVector = new double[poolingImg.Rows * poolingImg.Cols]; for (int j = 0; j < poolingImg.Rows; j++) { for (int i = 0; i < poolingImg.Cols; i++) { int[] PixelPool = new int[4]; PixelPool[0] = MatExtension.GetValue(srcImg, 2 * j, 2 * i); PixelPool[1] = MatExtension.GetValue(srcImg, 2 * j + 1, 2 * i); PixelPool[2] = MatExtension.GetValue(srcImg, 2 * j, 2 * i + 1); PixelPool[3] = MatExtension.GetValue(srcImg, 2 * j + 1, 2 * i + 1); MatExtension.SetValue(poolingImg, j, i, isMax ? (byte)PixelPool.Max() : (byte)PixelPool.Min()); inputVector[j * poolingImg.Cols + i] = Convert.ToDouble(isMax ? (byte)PixelPool.Max() : (byte)PixelPool.Min()); } } return(poolingImg); }