/// <summary>
        /// Get Roll Number.
        /// Roll Number Scanning.
        /// Reverse the 'roll_no' string.
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="blobs"></param>
        /// <returns></returns>
        public static string get_rollno(Sheet sheet, List<BLOB> blobs)
        {
            string roll_no = "";
            int roll_validity = 0;
            int roll_index = 0;
            for (int i = 0; i < 7; ++i)
            {
                int digit_index = 0;
                Coordinate[] coor = new Coordinate[10];

                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;
                coor[digit_index++] = sheet.roll[roll_index++].coordinate;

                for (int a = 0; a < 10; ++a)
                {
                    if (scan_blobs(coor[a], blobs))
                    {
                        roll_validity++;
                        roll_no += Convert.ToString(a);
                    }
                }
                if (roll_validity > 1 || roll_validity == 0)
                {
                    roll_no = "NOT_VALID";
                    continue;
                }
                roll_validity = 0;
            }

            char[] array = roll_no.ToCharArray();
            Array.Reverse(array);

            return new string(array);
 
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog 
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.InitialDirectory = Worker.templates_dir;
            // Set filter for file extension and default file extension 
            dlg.DefaultExt = ".txt";
            dlg.Filter = "XML Files (*.xml)|*.xml";

            // Display OpenFileDialog by calling ShowDialog method 
            Nullable<bool> result = dlg.ShowDialog();

            string filename = "";
            // Get the selected file name and display in a TextBox 
            if (result == true)
            {
                // Open document 
                filename = dlg.FileName;
                TextBox.Text = filename;
                
            }
            Select_DPI new_window = new Select_DPI();
            new_window.ShowDialog();
            sheet = new Sheet(filename);
            lbl_id.Content = sheet.id;
            lbl_choices.Content = sheet.choice;
            lbl_questions.Content = sheet.questions;

        }
        /// <summary>
        /// Creates the sheet object which contains the coordinates of the blobs.
        /// Performs scanning and validity on the recorded Choice/Numbers.
        /// </summary>
        /// <param name="blobs"></param>
        public static char[] get_answers(Sheet sheet, List<BLOB> blobs)
        {
            char[] answers = new char[100]; // Array of answers.

            // Scanning A choices.
            CHOICE[] A = new CHOICE[100];
            int ch = 0;
            for (int a = 0; a < 100; ++a)
            {
                A[a] = sheet.choices[ch];
                ch += 4;
            }
            for (int i = 0; i < 100; ++i)
            {
                if (scan_blobs(A[i].coordinate, blobs))
                    if (check_validity(answers[i]))
                        answers[i] = 'A';
                    else
                        answers[i] = '0';
            }
            
            // Scanning B choices.
            CHOICE[] B = new CHOICE[100];
            ch = 1;
            for (int a = 0; a < 100; ++a)
            {
                B[a] = sheet.choices[ch];
                ch += 4;
            }
            for (int i = 0; i < 100; ++i)
            {
                if (scan_blobs(B[i].coordinate, blobs))
                    if (check_validity(answers[i]))
                        answers[i] = 'B';
                    else
                        answers[i] = '0';
            }
            
            
            // Scanning C choices.
            CHOICE[] C = new CHOICE[100];
            ch = 2;
            for (int a = 0; a < 100; ++a)
            {
                C[a] = sheet.choices[ch];
                ch += 4;
            }
            for (int i = 0; i < 100; ++i)
            {
                if (scan_blobs(C[i].coordinate, blobs))
                    if (check_validity(answers[i]))
                        answers[i] = 'C';
                    else
                        answers[i] = '0'; 
            }
            
            // Scanning D choices.
            CHOICE[] D = new CHOICE[100];
            ch = 3;
            for (int a = 0; a < 100; ++a)
            {
                D[a] = sheet.choices[ch];
                ch += 4;
            }
            for (int i = 0; i < 100; ++i)
            {
                if (scan_blobs(D[i].coordinate, blobs))
                    if (check_validity(answers[i]))
                        answers[i] = 'D';
                    else
                        answers[i] = '0'; 
            }
            
            return answers;

        }
        /// <summary>
        /// Question Paper Scanning.
        /// Reverse the string.
        /// </summary>
        /// <param name="sheet"> Sheet object.</param>
        /// <param name="blobs"> Detected blobs.</param>
        /// <returns> Returns QP Code as a string. </returns>
        public static string get_qp_code(Sheet sheet, List<BLOB> blobs) 
        {
            string question_code = "";
            int question_validity = 0;
            int ques_index = 0;
            for (int i = 0; i < 5; ++i)
            {
                int digit_index = 0;
                Coordinate[] coor = new Coordinate[10];

                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;
                coor[digit_index++] = sheet.qp_code[ques_index++].coordinate;

                for (int a = 0; a < 10; ++a)
                {
                    if (scan_blobs(coor[a], blobs))
                    {
                        question_validity++;
                        question_code += Convert.ToString(a);
                    }
                }
                if (question_validity > 1 || question_validity == 0)
                {
                    question_code = "NOT_VALID";
                    continue;
                }
                question_validity = 0;
            }

            char[] array = question_code.ToCharArray();
            Array.Reverse(array);
            return new string(array);
        }
        /// <summary>
        /// Subject Code Scanning.
        /// Reverse the string as usual.
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="blobs"></param>
        /// <returns></returns>
        public static string get_subject_code (Sheet sheet, List<BLOB> blobs)
        {
            string subject_code = "";
            int sub_validity = 0;
            int sub_index = 0;
            for (int i = 0; i < 4; ++i)
            {
                int digit_index = 0;
                Coordinate[] coor = new Coordinate[10];

                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                coor[digit_index++] = sheet.sub_code[sub_index++].coordinate;
                
                for (int a = 0; a < 10; ++a)
                {
                    if (scan_blobs(coor[a], blobs))
                    {
                        sub_validity++;
                        subject_code += Convert.ToString(a);
                    }
                }
                if (sub_validity > 1 || sub_validity == 0)
                {
                    subject_code = "NOT_VALID";
                    continue;
                }
                sub_validity = 0;
            }


            char[] array = subject_code.ToCharArray();
            Array.Reverse(array);
            return new string(array);
        }
Example #6
0
 public void generate_results(Sheet sheet)
 {
     char[] ans = new char[100];
     Thread[] thread = new Thread[4];
     thread[0] = new Thread(() => { answer_key = new string(Coordinate_match.get_answers(sheet, useful)); });
     thread[1] = new Thread(() => { roll_no = Coordinate_match.get_rollno(sheet, useful); });
     thread[2] = new Thread(() => { qp_code = Coordinate_match.get_qp_code(sheet, useful); });
     thread[3] = new Thread(() => { subject_code = Coordinate_match.get_subject_code(sheet, useful); });
     for (int i = 0; i <= 3; ++i)
     {
         thread[i].Start();
         thread[i].Join();
     }
     
 }
Example #7
0
        /// <summary>
        /// Creates the sheet object which contains the coordinates of the blobs.
        /// Performs scanning and validity on the recorded Choice/Numbers.
        /// </summary>
        /// <param name="blobs"></param>
        public static char[] get_answers(Sheet sheet, List <BLOB> blobs)
        {
            char[] answers = new char[100]; // Array of answers.

            // Scanning A choices.
            CHOICE[] A  = new CHOICE[100];
            int      ch = 0;

            for (int a = 0; a < 100; ++a)
            {
                A[a] = sheet.choices[ch];
                ch  += 4;
            }
            for (int i = 0; i < 100; ++i)
            {
                if (scan_blobs(A[i].coordinate, blobs))
                {
                    if (check_validity(answers[i]))
                    {
                        answers[i] = 'A';
                    }
                    else
                    {
                        answers[i] = '0';
                    }
                }
            }

            // Scanning B choices.
            CHOICE[] B = new CHOICE[100];
            ch = 1;
            for (int a = 0; a < 100; ++a)
            {
                B[a] = sheet.choices[ch];
                ch  += 4;
            }
            for (int i = 0; i < 100; ++i)
            {
                if (scan_blobs(B[i].coordinate, blobs))
                {
                    if (check_validity(answers[i]))
                    {
                        answers[i] = 'B';
                    }
                    else
                    {
                        answers[i] = '0';
                    }
                }
            }


            // Scanning C choices.
            CHOICE[] C = new CHOICE[100];
            ch = 2;
            for (int a = 0; a < 100; ++a)
            {
                C[a] = sheet.choices[ch];
                ch  += 4;
            }
            for (int i = 0; i < 100; ++i)
            {
                if (scan_blobs(C[i].coordinate, blobs))
                {
                    if (check_validity(answers[i]))
                    {
                        answers[i] = 'C';
                    }
                    else
                    {
                        answers[i] = '0';
                    }
                }
            }

            // Scanning D choices.
            CHOICE[] D = new CHOICE[100];
            ch = 3;
            for (int a = 0; a < 100; ++a)
            {
                D[a] = sheet.choices[ch];
                ch  += 4;
            }
            for (int i = 0; i < 100; ++i)
            {
                if (scan_blobs(D[i].coordinate, blobs))
                {
                    if (check_validity(answers[i]))
                    {
                        answers[i] = 'D';
                    }
                    else
                    {
                        answers[i] = '0';
                    }
                }
            }

            return(answers);
        }