Example #1
0
        public string[] findText()
        {
            string fontFile = directory + fontName + mlpFileExtension;
            HTuple ocrHandle;

            if (image != null)
            {
                textModel.CreateTextModelReader("auto", fontFile);
                //ocrMlp.ReadOcrClassMlp(fontFile);
                HOperatorSet.ReadOcrClassMlp(fontFile, out ocrHandle);
                string Expression = @"([A-Z]{3}[0-9]{5}.?[A-Z][0-9]{4}[A-Z][0-9]{4})";

                HTextResult textresu = textModel.FindText(image);

                // HObject chars = textresu.GetTextObject("all_lines");
                HTuple   resultValue = textresu.GetTextResult("num_lines");
                string[] textFound   = new string[resultValue];

                for (int i = 0; i < resultValue; i++)
                {
                    HTuple  clas, confidence, word, score;
                    HTuple  resultName = new HTuple("line", i);
                    HObject chars      = textresu.GetTextObject(resultName);
                    HOperatorSet.DoOcrWordMlp(chars, image, ocrHandle, Expression, 3, 5, out clas, out confidence, out word, out score);
                    // ocrMlp.DoOcrWordMlp((HRegion)chars, image, Expression, 3, 5, out confidence, out word, out score);
                    textFound[i] = word;
                }
                return(textFound);
            }
            return(null);
        }
Example #2
0
        private void hSmartWindowControl1_HInitWindow(object sender, EventArgs e)
        {
            HWindow    hWindow    = (sender as HSmartWindowControl).HalconWindow;
            HTextModel hTextModel = new HTextModel("auto", "Industrial_Rej");
            HImage     hImage     = new HImage("ocr/medication_package_02_right");


            HTextResult hTextResult = hImage.FindText(hTextModel);
            HObject     hTextLine   = hTextResult.GetTextObject(new HTuple("line", 0));

            hWindow.SetColored(3);
            hWindow.DispImage(hImage);
            hWindow.DispObj(hTextLine);
            hSmartWindowControl1.SetFullImagePart(null);
        }