Exemple #1
0
        /// <summary>
        /// Parallelized OCR Orientation Confidence Detector, this method will run ocr on 
        /// an image and its corresponding reversed images and return the confidence and 
        /// both the ocrdata objects
        /// </summary>
        /// <param name="regs">Images with default regular orientation</param>
        /// <param name="revs">Images with reversed orientation to default</param>
        /// <param name="mode">OCR accuracy mode</param>
        /// <param name="lang">OCR languages</param>
        /// <param name="enableTimer">Enable timer for diagnostic purposes</param>
        /// <returns>Tuple containing confidence, regular ocrdata and reversed ocrdata.
        ///  Positive confidence is for Regular where as negative 
        ///  confidences is for Reversed</returns>
        public static Tuple<long, OcrData, OcrData>[] ParallelDetectOrientation(
            Bitmap[] regs,
            Bitmap[] revs,
            Accuracy mode = Accuracy.High,
            string lang = "eng",
            bool enableTimer = false)
        {
            if (regs.Length != revs.Length)
            {
                throw new ArgumentException("Input Arrays must be same length!");
            }

            // create new array and copy over image references
            int pivot = regs.Length;
            Bitmap[] images = new Bitmap[regs.Length + revs.Length];
            Array.Copy(regs, images, pivot);
            Array.Copy(revs, 0, images, pivot, pivot);

            // Run Parallel Recognition on the arrays
            OcrData[] datas = ParallelRecognize(images, pivot + pivot, mode, lang, enableTimer);

            // Extract results and calculate confidence
            Tuple<long, OcrData, OcrData>[] results = new Tuple<long, OcrData, OcrData>[pivot];
            for (int ii = 0; ii < pivot; ii++)
            {
                OcrData reg = datas[ii];
                OcrData rev = datas[ii + pivot];

                // If postive we are confident about the current orientation
                // if negative we are not confident about the current orientation
                long confidence = rev.Cost - reg.Cost;
                results[ii] = new Tuple<long, OcrData, OcrData>(confidence, reg, rev);
            }
            return results;
        }
Exemple #2
0
        /// <summary>
        ///   Parallelized Recognize Function takes in a list or array of images,
        ///   A specified length and for each image returns an OCRData object
        /// </summary>
        /// <param name="images"> Array or List of Bitmaps </param>
        /// <param name="length"> Number of items to be Recognized from the array </param>
        /// <param name="mode"> Accuracy Mode </param>
        /// <param name="lang"> Desired OCR Language </param>
        /// <param name="enableTimer"> Enables OCR Scan Timer if true </param>
        /// <returns> </returns>
        public static OcrData[] ParallelRecognize(IEnumerable<Bitmap> images,
            int length,
            Accuracy mode = Accuracy.High,
            string lang = "eng",
            bool enableTimer = false)
        {
            Tuple<int, Bitmap>[] indexedImages = new Tuple<int, Bitmap>[length];
            int index = 0;
            foreach (Bitmap image in images)
            {
                if (index >= length)
                {
                    break;
                }
                indexedImages[index] = new Tuple<int, Bitmap>(index, image);

                index += 1;
            }

            ConcurrentDictionary<int, OcrData> safeMap = new ConcurrentDictionary<int, OcrData>();

            Parallel.ForEach(indexedImages, pair =>
                {
                    int position = pair.Item1;
                    Bitmap image = pair.Item2;
                    safeMap[position] = Recognize(image, mode, lang, enableTimer);
                });

            OcrData[] data = new OcrData[length];
            foreach (KeyValuePair<int, OcrData> kvpair in safeMap)
            {
                data[kvpair.Key] = kvpair.Value;
            }

            return data;
        }
Exemple #3
0
 public static bool IsBetter(OcrData first, OcrData second)
 {
     return(first.Cost < second.Cost);
 }