예제 #1
0
        private void LoadHandTrainingPatternsFromDir(string path)
        {
            try
            {
                byte[] TrainPatterns;
                MNistHeight = 32;
                MNistWidth = 32;
                MNistSize = MNistWidth * MNistHeight;
                int TrainingLabelCount = 10;
                int LabelImageCount = 20;
                TrainingPatternsCount = TrainingLabelCount*LabelImageCount;

                TrainPatterns = new byte[TrainingPatternsCount * MNistSize];
                unsafe
                {

                    for (int ii = 0; ii < TrainingLabelCount; ii++)
                    {
                        string type = ii.ToString("D1");
                        //Image<Bgr, Byte> image = new Image<Bgr, byte>(path + "\\" + type + ".jpg").Resize(32, 32, Emgu.CV.CvEnum.INTER.CV_INTER_AREA); //Read the files as an 8-bit Bgr image  
                        //Image<Gray, Byte> gray = image.Convert<Gray, Byte>(); //Convert it to Grayscale
                        Capture cap = new Capture(path + "\\" + type + ".MOV");
                        for (int i = 0; i < LabelImageCount; i++)
                        {
                            Image<Gray, Byte> gray = cap.QueryGrayFrame().Resize(32, 32, Emgu.CV.CvEnum.INTER.CV_INTER_AREA);
                            for (int j = 0; j < MNistSize; j++)
                            {
                                TrainPatterns[ii * MNistSize * LabelImageCount + i * MNistSize + j] = ((byte*)gray.MIplImage.imageData + j)[0];
                            }
                        }
                        cap.Dispose();
                    }
                }
                MNISTTraining = new ByteImageData[TrainingPatternsCount];
                Parallel.For(0, TrainingPatternsCount, parallelOption, j =>
                {
                    int label = j / LabelImageCount;
                    ByteImageData imageData = new ByteImageData(label, new byte[MNistSize]);
                    for (int i = 0; i < MNistSize; i++)
                    {
                        imageData.Image[i] = TrainPatterns[(j * MNistSize) + i];
                    }
                    MNISTTraining[j] = imageData;
                });

            }
            catch (Exception)
            {
                throw;
            }
        }
예제 #2
0
		private void LoadTestingPatternsFromFile(string path)
		{
			try
			{
				byte[] TestPatterns;
				using (FileStream fileStreamTestPatterns = System.IO.File.Open(path + @"\t10k-images-idx3-ubyte", FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					byte[] magicNumber = new byte[16];
					fileStreamTestPatterns.Read(magicNumber, 0, 16);
					//DataType dataType = (DataType)magicNumber[2];
					//int dimensions = (int)magicNumber[3];

					TestingPatternsCount = magicNumber[7] + (magicNumber[6] * 256) + (magicNumber[5] * 65536) + (magicNumber[4] * 16777216);
					MNistHeight = magicNumber[11] + (magicNumber[10] * 256) + (magicNumber[9] * 65536) + (magicNumber[8] * 16777216);
					MNistWidth = magicNumber[15] + (magicNumber[14] * 256) + (magicNumber[13] * 65536) + (magicNumber[12] * 16777216);
					MNistSize = MNistWidth * MNistHeight;

					TestPatterns = new byte[TestingPatternsCount * MNistSize];
					fileStreamTestPatterns.Seek(16, SeekOrigin.Begin);
					fileStreamTestPatterns.Read(TestPatterns, 0, TestingPatternsCount * MNistSize);
				}

				byte[] TestLabels;
				using (FileStream fileStreamTestLabels = System.IO.File.Open(path + @"\t10k-labels-idx1-ubyte", FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					TestLabels = new byte[TestingPatternsCount];
					fileStreamTestLabels.Seek(8, SeekOrigin.Begin);
					fileStreamTestLabels.Read(TestLabels, 0, TestingPatternsCount);
				}

				MNISTTesting = new ByteImageData[TestingPatternsCount];
				Parallel.For(0, TestingPatternsCount, parallelOption, j =>
				{
					ByteImageData pattern = new ByteImageData(TestLabels[j], new byte[MNistSize]);
					for (int i = 0; i < MNistSize; i++)
					{
						pattern.Image[i] = TestPatterns[(j* MNistSize ) + i];
					}
					MNISTTesting[j] = pattern;
				});

			}
			catch (Exception)
			{
				throw;
			}
		}
예제 #3
0
        private void LoadHandTestingPatternsFromDir(string path)
        {
            try
            {
                byte[] TestPatterns;
                MNistHeight = 32;
                MNistWidth = 32;
                MNistSize = MNistWidth * MNistHeight;
                int TrainingLabelCount = 9;
                int LabelImageCount = 100;
                TestingPatternsCount = TrainingLabelCount * LabelImageCount;
                TestPatterns = new byte[TestingPatternsCount * MNistSize];
                //Capture cap = new Capture(@"D:\ebooks\hand gestrue recognition\hand data set\mov\0.MOV");
                unsafe
                {

                    for (int ii = 0; ii < TrainingLabelCount; ii++)
                    {
                        string type = ii.ToString("D1");
                        //Image<Bgr, Byte> image = new Image<Bgr, byte>(path + "\\" + type + ".jpg").Resize(32, 32, Emgu.CV.CvEnum.INTER.CV_INTER_AREA); //Read the files as an 8-bit Bgr image  
                        //Image<Gray, Byte> gray = image.Convert<Gray, Byte>(); //Convert it to Grayscale
                        Capture cap = new Capture(path + "\\" + type + ".MOV");
                        for(int i =0; i<200;i++)
                        {
                            cap.QueryGrayFrame();//skip first 200 frames
                        }
                        for (int i = 0; i < LabelImageCount; i++)
                        {
                            Image<Gray, Byte> gray = cap.QueryGrayFrame().Resize(32, 32, Emgu.CV.CvEnum.INTER.CV_INTER_AREA);
                            for (int j = 0; j < MNistSize; j++)
                            {
                                TestPatterns[ii * MNistSize * LabelImageCount + i * MNistSize + j] = ((byte*)gray.MIplImage.imageData + j)[0];
                            }
                        }
                        cap.Dispose();
                    }
                }


                MNISTTesting = new ByteImageData[TestingPatternsCount];
                Parallel.For(0, TestingPatternsCount, parallelOption, j =>
                {
                    ByteImageData pattern = new ByteImageData(j / LabelImageCount, new byte[MNistSize]);
                    for (int i = 0; i < MNistSize; i++)
                    {
                        pattern.Image[i] = TestPatterns[(j * MNistSize) + i];
                    }
                    MNISTTesting[j] = pattern;
                });

            }
            catch (Exception)
            {
                throw;
            }
        }