Example #1
0
        public static (List <AnswerData>, List <InfoData>) GetAnswerData(Template template, System.Drawing.Bitmap bitmap, bool getInfo = false)
        {
            OMR.IOMR omr = new OMR.OMRv1();
            (List <OMR.PointProperty> point, List <int> rowSize) = omr.GetPositionPoint(bitmap, bitmap.Width * template.CircleSize / template.Image.Width, true);
            if (point.Count != template.PointsList.Count || rowSize.Count != template.RowSize.Count)
            {
                return(null, null);
            }
            for (int i = 0; i < rowSize.Count; i++)
            {
                if (rowSize[i] != template.RowSize[i])
                {
                    return(null, null);
                }
            }

            var key  = new List <AnswerData>();
            var info = new List <InfoData>();

            foreach (var item in template.AnsData)
            {
                for (int i = 0; i < item.Count; i++)
                {
                    int select = 0;
                    for (int j = 0; j < item.Length; j++)
                    {
                        int x = item.StartX;
                        int y = item.StartY;
                        if (item.OrderType == Template.TemplateData.Type.Horizontal)
                        {
                            x += i;
                            y += j;
                        }
                        else
                        {
                            x += j;
                            y += i;
                        }
                        if (point[template.RowOffset[y] + x].IsCheck)
                        {
                            if (select == 0)
                            {
                                select = j + 1;
                            }
                            else
                            {
                                select = -1;
                                break;
                            }
                        }
                    }
                    key.Add(new AnswerData(item.Offset + i, item.Length, select));
                }
            }

            if (getInfo)
            {
                foreach (var item in template.InfoData)
                {
                    string sum = "";
                    for (int i = 0; i < item.Count; i++)
                    {
                        int value = 0;
                        for (int j = 0; j < item.Length; j++)
                        {
                            int x = item.StartX + (item.OrderType == Template.TemplateData.Type.Horizontal ? i : 0);
                            int y = item.StartY + (item.OrderType == Template.TemplateData.Type.Horizontal ? 0 : i);
                            if (item.OrderType == Template.TemplateData.Type.Horizontal)
                            {
                                y += j;
                            }
                            else
                            {
                                x += j;
                            }
                            if (point[template.RowOffset[y] + x].IsCheck)
                            {
                                if (value == 0)
                                {
                                    value = j;
                                }
                                else
                                {
                                    value = 0;
                                    break;
                                }
                            }
                        }
                        sum += value.ToString();
                    }
                    info.Add(new InfoData(item.Name, item.Count, long.Parse(sum)));
                }
            }

            return(key, info);
        }
Example #2
0
        public static List <OMR.PointProperty> AreaToPointList(int x, int y, int w, int h, Template template)
        {
            List <OMR.PointProperty> pointProperties = new List <OMR.PointProperty>();

            for (int row = y; row < h + y; row++)
            {
                for (int col = x; col < w + x; col++)
                {
                    pointProperties.Add(template.PointsList[template.RowOffset[row] + col]);
                }
            }
            return(pointProperties);
        }