Example #1
0
        public static ReviewCounter GetManualReviewCollection(IRecognitionForm recognizeForm, VerificationParameters parameters, IRecognitionForm answers = null, bool[][][] reviewed = null)
        {
            ReviewCounter reviewCounter = new ReviewCounter();

            for (int i = 0; i < recognizeForm.Pages.Count; i++)
            {
                Page page = recognizeForm.Pages[i];
                for (int j = 0; j < page.Fields.Count; j++)
                {
                    Field field = page.Fields[j];

                    if (field == null)
                    {
                        continue;
                    }

                    field.PageNumber = page.PageNumber;

                    OmrField omrField = field as OmrField;

                    if (omrField != null)
                    {
                        for (int k = 0; k < omrField.Fields.Count; k++)
                        {
                            OmrCollection omr = omrField.Fields[k];
                            reviewCounter.TotalCounts++;

                            //string errors = "The field confidence value is below the required confidence value, the field does not have exactly one bubble filled in, the field has the same value as the answer key, the field has a different value from the answer key, ";

                            List <string>          errors        = new List <string>();
                            VerificationParameters erroredParams = new VerificationParameters(false, false, false, false, parameters.Threshold, false, false);

                            ReviewParameters rp = null;
                            if (omr.Tag != null)
                            {
                                rp            = (ReviewParameters)omr.Tag;
                                erroredParams = rp.ErroredParameters;
                            }


                            string answerVals = null;
                            erroredParams.Threshold = omr.Confidence;

                            if (/* parameters.UseThreshold && */ omr.Confidence < parameters.Threshold)
                            {
                                errors.Add("OMR confidence value too low");
                                erroredParams.UseThreshold = true;
                                reviewCounter.BelowThreshold++;
                            }

                            //                        if (parameters.UseExactlyOneBubble)
                            {
                                int selectedCells = omr.Fields.Count <OmrBubble>(delegate(OmrBubble bub) { return(bub.IsChecked); });
                                if (selectedCells != 1)
                                {
                                    errors.Add("Does not have exactly one bubble filled in");
                                    erroredParams.UseExactlyOneBubble = true;
                                    reviewCounter.NotExactlyOneBubble++;
                                }
                            }
                            erroredParams.UseValueChanged = omr.Value != omr.OriginalValue;

                            if (answers != null && answers.Pages.Count > 0)
                            {
                                OmrField ansField = answers.Pages[i].Fields[j] as OmrField;

                                OmrFieldResult ofr = (OmrFieldResult)ansField.Result;

                                string value = ansField.Fields[k].Value;
                                answerVals = value;

                                if (/* parameters.UseAgreeWithKey && */ omr.Value == value)
                                {
                                    errors.Add("Same value as answer key");
                                    erroredParams.UseAgreeWithKey = true;
                                    reviewCounter.AgreeWithKey++;
                                }
                                if (/* parameters.UseDisagreeWithKey && */ omr.Value != value)
                                {
                                    errors.Add("Different value from answer key");
                                    erroredParams.UseDisagreeWithKey = true;
                                    reviewCounter.DisagreeWithKey++;
                                }
                            }

                            //page.Image.Page = omrField.PageNumber + 1;
                            if (rp != null)
                            {
                                rp.ErroredParameters = erroredParams;
                                omr.Tag = rp;
                            }
                            else
                            {
                                omr.Tag = new ReviewParameters(omrField.GetValues(), errors, answerVals, recognizeForm.Id, erroredParams, page.PageNumber);
                            }

                            if (errors.Count > 0)
                            {
                                if (reviewed != null)
                                {
                                    bool             flag = reviewed[i][j][k];
                                    ReviewParameters rps  = (ReviewParameters)omr.Tag;
                                    rps.ReviewRequired = flag;

                                    VerificationParameters vp = rps.ErroredParameters;
                                    vp.IsReviewed         = !flag;
                                    rps.ErroredParameters = vp;
                                }
                            }
                        }
                    }
                }
            }

            return(reviewCounter);
        }
Example #2
0
        // this prepares the workspace for serialization to disk
        public void Pack(string filename)
        {
            this.locationOnDisk = filename;

            filenames = new List <string>();

            using (MemoryStream ms = new MemoryStream())
            {
                template.Save(ms);
                templateBytes = ms.GetBuffer();
                ms.Close();
            }

            if (answers != null)
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    answers.Save(ms);
                    answerBytes = ms.GetBuffer();
                    ms.Close();
                }
            }

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, myImages);
                filepathDictionaryBytes = ms.GetBuffer();

                ms.Close();
            }

            reviewRequiredStatus = new bool[results.Count][][][];

            resultsBytes = new byte[results.Count][];
            for (int i = 0; i < results.Count; i++)
            {
                IRecognitionForm frm = results[i];

                reviewRequiredStatus[i] = new bool[frm.Pages.Count][][];

                for (int j = 0; j < frm.Pages.Count; j++)
                {
                    reviewRequiredStatus[i][j] = new bool[frm.Pages[j].Fields.Count][];

                    for (int k = 0; k < frm.Pages[j].Fields.Count; k++)
                    {
                        if (frm.Pages[j].Fields[k] is OmrField)
                        {
                            reviewRequiredStatus[i][j][k] = ((OmrField)frm.Pages[j].Fields[k]).Fields.ConvertAll <bool>(delegate(OmrCollection oc) { ReviewParameters rp = oc.Tag as ReviewParameters; return(rp != null ? rp.ReviewRequired : false); }).ToArray();
                        }
                    }
                }

                using (MemoryStream ms = new MemoryStream())
                {
                    frm.Save(ms);
                    resultsBytes[i] = ms.GetBuffer();
                    ms.Close();
                }
            }
        }