Beispiel #1
0
        public string GetTypeString()
        {
            string result = "";

            switch (type)
            {
            case "object":
                result = @ref;
                break;

            case "array":
                return(items.GetTypeString() + "[]");

            case "string":
                if (@enum != null && @enum.Count > 0)
                {
                    return($"({string.Join(" | ", @enum.Select(x => x is string ? "'" + Regex.Escape(x.ToString()) + "'" : x))})");
                }
                return("string");

            default:
                result = type ?? @ref;
                break;
            }

            if (result?.StartsWith("#") ?? false)
            {
                return(PreProcessing.FixTypeName(result.Split('/').Last()));
            }

            return(result != null?PreProcessing.FixTypeName(result) : null);
        }
Beispiel #2
0
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = PreProcessing.Convert(values[i], null, null, culture);
            }

            var value = MultiValueConverter.Convert(values, null, parameter, culture);

            return(PostProcessing.Convert(value, null, null, culture));
        }
 /// <summary>
 ///   Resolves the input reference against the specified parent template. E.g. resolves the internally referenced input, and preprocesses this value as appropriate.
 /// </summary>
 /// <param name = "template"></param>
 /// <returns></returns>
 public object Resolve(FluTeCoreInstance template)
 {
     if (template.Inputs.ContainsKey(Key))
     {
         var input = (IBoundInput)template.Inputs[Key];
         return(PreProcessing.Invoke(input.Value));
     }
     else
     {
         throw new KeyNotFoundException("An input reference tried to resolve an input that doesn't exist in the template.");
     }
 }
Beispiel #4
0
        public static void prepareDocuments(List <Document> documents, HashSet <string> classifierGrams)
        {
            var filenames = from fullFilename
                            in Directory.EnumerateFiles("raw_texts/", "*.txt", SearchOption.AllDirectories)
                            select Path.GetFullPath(fullFilename);

            List <string> list = filenames.ToList();
            StreamReader  sr2  = new StreamReader("stop_words.txt", Encoding.GetEncoding("ISO-8859-9"));
            Language      tr   = LanguageFactory.Create(LanguageType.Turkish);

            char[]   seperators = { ' ', '\n', '\t', '\r', '\0' };
            string[] stopWords  = sr2.ReadToEnd().Split('\n');
            Dictionary <string, int>         allGrams = new Dictionary <string, int>();
            List <Dictionary <string, int> > grams    = new List <Dictionary <string, int> >();

            Parallel.ForEach(list, i =>
            {
                StreamReader sr  = new StreamReader(i, Encoding.GetEncoding("ISO-8859-9"));
                string cleanData = PreProcessing.editFile(i, sr, sr2, tr, seperators, stopWords);
                var gram         = CreateGramsFrequencies.make2Gram(cleanData).Concat(CreateGramsFrequencies.make3gram(cleanData)).ToDictionary(e => e.Key, e => e.Value);//2gram ile 3 grami birlestir
                grams.Add(gram);
                documents.Add(new Document(Path.GetFileNameWithoutExtension(i), Directory.GetParent(i).Name, gram));

                sr.Close();
            });

            foreach (var i in grams)
            {
                foreach (KeyValuePair <string, int> ix in i)
                {
                    if (!allGrams.ContainsKey(ix.Key))
                    {
                        allGrams.Add(ix.Key, ix.Value);
                    }
                    else
                    {
                        allGrams[ix.Key] += ix.Value;
                    }
                }
            }


            foreach (KeyValuePair <string, int> gram in allGrams)
            {
                if (gram.Value >= 50)
                {
                    if (!classifierGrams.Contains(gram.Key))
                    {
                        classifierGrams.Add(gram.Key);
                    }
                }
            }
        }
Beispiel #5
0
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            value = PostProcessing.ConvertBack(value, null, null, culture);

            var values = MultiValueConverter.ConvertBack(value, null, parameter, culture);

            for (int i = 0; i < values.Length; i++)
            {
                values[i] = PreProcessing.ConvertBack(values[i], null, null, culture);
            }

            return(values);
        }
Beispiel #6
0
        private void btnReSampling_Click(object sender, EventArgs e)
        {
            var preProc = new PreProcessing();

            var traceGroup           = _drawingInk.Ink.ToTraceGroup();
            var resamplingTraceGroup = preProc.ResampleTraceGroup(traceGroup);

            _resultInk.Enabled = false;
            _resultInk.Ink     = resamplingTraceGroup.ToInk();
            _resultInk.Enabled = true;

            txtDrawingResult.Text = ReadTraceGroupInUnipenFormat(resamplingTraceGroup);
        }
        private void Predict()
        {
            string filePath = @"..\..\CNN\Configs\95,11__9__AFDAB.json";

            Bitmap resized       = new Bitmap(bmp, new Size(28, 28));
            Bitmap preProcessing = null;

            if (processingActive)
            {
                preProcessing = PreProcessing.MedianSmoothing(resized, 3);
            }
            else
            {
                preProcessing = resized;
            }
            Bitmap preproccessedImage = new Bitmap(preProcessing, new Size(bmp.Width, bmp.Height));

            pbProccessedImage.Image = preproccessedImage;

            resized  = preProcessing;
            input[0] = new Matrix(resized.Width, resized.Height);
            bytes    = new byte[28][];

            for (int i = 0; i < input[0].rows; i++)
            {
                bytes[i] = new byte[28];
                for (int j = 0; j < input[0].cols; j++)
                {
                    Color c = resized.GetPixel(j, i);
                    input[0][i, j] = 255f - c.R;
                    bytes[i][j]    = (byte)(255 - c.R);
                }
            }
            input[0].Normalize(0f, 255f, 0f, 1f);

            CnnNetwork cnn    = new CnnNetwork(filePath);
            Matrix     output = cnn.Predict(input);

            maxIndex = output.GetMaxRowIndex();
            string guessText;

            guessText     = string.Format("This is %{0:f2} a {1}", output[maxIndex, 0] * 100, maxIndex);
            lblGuess.Text = guessText;

            lstOutput.Items.Clear();
            for (int i = 0; i < output.rows; i++)
            {
                lstOutput.Items.Add(output[i, 0].ToString("F3"));
            }
        }
Beispiel #8
0
        private void btnSmooth_Click(object sender, EventArgs e)
        {
            var traceGroup = _drawingInk.Ink.ToTraceGroup();

            //txtUnipen.Text = ReadTraceGroupInUnipenFormat(traceGroup);

            var preProc       = new PreProcessing();
            var newTraceGroup = preProc.SmoothenTraceGroup(traceGroup);

            _resultInk.Enabled = false;
            _resultInk.Ink     = newTraceGroup.ToInk();
            _resultInk.Enabled = true;

            txtDrawingResult.Text = ReadTraceGroupInUnipenFormat(newTraceGroup);
        }
Beispiel #9
0
        private void LoadImage()
        {
            var openFileDialog = new OpenFileDialog
            {
                Filter = "images(*.png;*.jpg;*.bmp)|*.png;*.bmp;*jpg",
                Title  = "打开图片"
            };

            if (openFileDialog.ShowDialog() == true)
            {
                ImagePath            = openFileDialog.FileName;
                currentPreProcessing = new PreProcessing(ImagePath);
                InputSource          = currentPreProcessing.originalBitmap.ToBitmapSource();
            }
        }
Beispiel #10
0
        private void btnEuclidean_Click(object sender, EventArgs e)
        {
            var featureExtractor = new PointFloatShapeFeatureExtractor();
            var preProc          = new PreProcessing();

            var traceGroup        = _drawingInk.Ink.ToTraceGroup();
            var sampledTraceGroup = preProc.ResampleTraceGroup(chkIsNormalized.Checked?preProc.NormalizeSize(traceGroup): traceGroup);
            var features          = featureExtractor.ExtractFeature(sampledTraceGroup);

            var testTraceGroup        = _resultInk.Ink.ToTraceGroup();
            var sampledTestTraceGroup = preProc.ResampleTraceGroup(chkIsNormalized.Checked?preProc.NormalizeSize(testTraceGroup): testTraceGroup);
            var testFeatures          = featureExtractor.ExtractFeature(sampledTestTraceGroup);

            var eucDistance = featureExtractor.ComputeEuclideanDistance(features, testFeatures);

            MessageBox.Show(@"Euclidean Distance = " + eucDistance);
        }
Beispiel #11
0
        public string GetTypeString()
        {
            string result = "";

            switch (type)
            {
            case "object":
                result = this is Parameter param ? param.@ref : "object";
                break;

            case "array":
                return(items.GetTypeString() + "[]");

            case "string":
                if (@enum != null && @enum.Count > 0)
                {
                    return($"({string.Join(" | ", @enum.Select(x => x is string ? "'" + Regex.Escape(x.ToString()) + "'" : x))})");
                }
                return("string");

            default:
                if (type != null)
                {
                    result = type;
                    break;
                }

                if (this is Parameter param_)
                {
                    result = param_.@ref;
                    result = result ?? ((param_.@in == "path") ? "string" : param_.schema.GetTypeString());
                    result = result ?? "object";
                }
                break;
            }

            if (result?.StartsWith("#") ?? false)
            {
                return(PreProcessing.FixTypeName(result.Split('/').Last()));
            }

            return(result != null?PreProcessing.FixTypeName(result) : null);
        }
Beispiel #12
0
        public void Run()
        {
            //Contour<Point> contours = grayImage.FindContours();
            //List<Point> listPoints = contours.ToList();

            List <Point> listPoints = PreProcessing.FindContours(grayImage);

            //foreach (Point i in listPoints)
            //{

            //    grayImage.Draw(new Rectangle(i, new Size(0, 0)), new Gray(0), 1);
            //    pictureBoxContour.Image = grayImage.ToBitmap();
            //    Thread.Sleep(10);

            //}
            //MessageBox.Show(listPoints.Count.ToString());
            Image <Bgr, Byte> contoursGraph = PreProcessing.DrawContoursGraph(PreProcessing.BuildContoursGraph(listPoints));

            //contoursGraph = contoursGraph.Resize(0.45, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
            pictureBoxBinary.Image = contoursGraph.ToBitmap();
        }
Beispiel #13
0
        public void PreProcess()
        {
            Image <Bgr, Byte> originalImage = new Image <Bgr, Byte>(@"D:\Master\hand.jpg");

            originalImage = PreProcessing.Cropping(originalImage, new Rectangle(0 + 10, 0 + 10, originalImage.Width - 30, originalImage.Height - 30));
            originalImage = originalImage.Resize(0.45, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
            //originalImage = originalImage.Rotate(90.0, new Bgr(255, 255, 255));
            pictureBoxOriginal.Image = originalImage.ToBitmap();

            grayImage            = PreProcessing.Convert2Grayscale(originalImage);
            grayImage            = PreProcessing.NoiseFilter(grayImage, 9);
            pictureBoxGray.Image = grayImage.ToBitmap();



            grayImage = PreProcessing.Binarization(grayImage, new Gray(255.0));
            pictureBoxBinary.Image = grayImage.ToBitmap();

            grayImage = PreProcessing.EdgeDetection(grayImage);



            pictureBoxContour.Image = grayImage.ToBitmap();
            int count = 0;

            for (int i = 0; i < grayImage.Height; i++)
            {
                for (int j = 0; j < grayImage.Width; j++)
                {
                    if (grayImage[i, j].Equals(new Gray(255)))
                    {
                        count++;
                    }
                }
            }
            MessageBox.Show(count.ToString());
            Thread t = new Thread(new ThreadStart(Run));

            t.Start();
        }
Beispiel #14
0
 public TrainRecognizer()
 {
     _featureExtractor = new PointFloatShapeFeatureExtractor();
     _inkFile          = new InkFile();
     _preProc          = new PreProcessing();
 }
Beispiel #15
0
        private int _numOfChoice = 5; // K value in k-NN

        public NNRecognizer()
        {
            _featureExtractor = new PointFloatShapeFeatureExtractor();
            _preProc          = new PreProcessing();
        }
 public void PreProcessTweets()
 {
     PreProcessing.WritePreProcessedTweets();
 }
Beispiel #17
0
        /*
         * This method responsible for calling detectWords method
         */
        /// <summary>
        /// This method running 6 ocr process in pararell to detect ids in the receipt.
        /// </summary>
        /// <param name="imgName"></param>
        /// <param name="img"></param>
        private void InitReceiptsList(string imgName, Image img)
        {
            _logger.Debug($"Initializing Receipt list imgName: {imgName}");
            PreProcessing preProccessing = new PreProcessing(img);
            OcrResult     ocrResults     = null;

            try
            {
                _logger.Debug("Ocr Processing started");
                _logger.Debug($"OcrRead imgName: {imgName} - Mode1");
                try
                {
                    ocrResults = ocr.Read(preProccessing.GetMode1());
                }
                catch (Exception e)
                {
                    _logger.Error($"Read", e);
                }
                if (ocrResults.Pages.Count > 0)
                {
                    Receipt receipt = new Receipt(ocrResults.Pages[0].Width, ocrResults.Pages[0].Height, imgName, preProccessing.GetImageInNewResolution(), ConvertTo24bpp(img));//create receipt object with sizes and name
                    DetectWords(ocrResults, receipt);
                    var mode2 = new Task(() =>
                    {
                        try
                        {
                            _logger.Debug($"OcrRead imgName: {imgName} - New Resolution");
                            DetectWords(ocr.Read(preProccessing.GetMode2()), receipt);
                        }
                        catch (Exception e)
                        {
                            _logger.Error($"Error - OcrRead imgName: {imgName} - New Resolution", e);
                        }
                    });

                    var mode3 = new Task(() =>
                    {
                        try
                        {
                            _logger.Debug($"OcrRead imgName: {imgName} - Mode3");
                            DetectWords(ocr.Read(preProccessing.GetMode3()), receipt);
                        }
                        catch (Exception e)
                        {
                            _logger.Error($"Error - OcrRead imgName: {imgName} - Mode3", e);
                        }
                    });

                    var mode4 = new Task(() =>
                    {
                        try
                        {
                            _logger.Debug($"OcrRead imgName: {imgName} - Mode4");
                            var image = preProccessing.GetMode4();
                            DetectWords(ocr.Read(new Bitmap(image)), receipt);
                        }
                        catch (Exception e)
                        {
                            _logger.Error($"Error - OcrRead imgName: {imgName} - Mode4", e);
                        }
                    });

                    var mode5 = new Task(() =>
                    {
                        try
                        {
                            _logger.Debug($"OcrRead imgName: {imgName} - Mode5");
                            var image = preProccessing.GetMode5();
                            DetectWords(ocr.Read(new Bitmap(image)), receipt);
                        }
                        catch (Exception e)
                        {
                            _logger.Error($"Error - OcrRead imgName: {imgName} - Mode5", e);
                        }
                    });

                    var mode6 = new Task(() =>
                    {
                        try
                        {
                            _logger.Debug($"OcrRead imgName: {imgName} - Mode6");
                            var image = preProccessing.GetMode6();
                            DetectWords(ocr.Read(new Bitmap(image)), receipt);
                        }
                        catch (Exception e)
                        {
                            _logger.Error($"Error - OcrRead imgName: {imgName} - Mode6", e);
                        }
                    });


                    mode2.Start();
                    mode3.Start();
                    mode4.Start();
                    mode2.Wait();
                    mode3.Wait();
                    mode4.Wait();

                    mode5.Start();
                    mode6.Start();
                    mode5.Wait();
                    mode6.Wait();

                    //add receipt after trying all modes
                    _logger.Debug($"Adding receipt {receipt.GetName()} to list of ready receits");

                    this.receipts.Add(receipt);
                }
            }
            catch (Exception e)
            {
                _logger.Error($"Error OcrRead imgName: {imgName} - Mode1", e);
            }
        }