Ejemplo n.º 1
0
        private bool fix_orientiation()
        {
            bool flag = true;

            deskew();

            flag = search_left_marker(0, 0, 20);
            if (flag)
            {
                flag = search_right_marker(img.Width / 2, 0, 20);
            }
            if (flag)
            {
                flag = search_bottom_marker(0, img.Size.Height / 2, 20);
            }

            /*
             * int percent = findcircle(x_lc, y_lc, width/2);
             * if (percent <= 5)
             * {
             *  flag = false;
             * }*/
            int diff_x = 0, diff_y = 0, n_width = width, n_height = height;

            diff_x = lc_x - 10;
            diff_y = lc_y - 10;


            try
            {
                img = cropAtRect(img, new Rectangle(lc_x, lc_y, rc_x + 20 - diff_x, bc_y + 20 - diff_y));
            }

            catch (Exception ex)
            {
                MessageBox.Show("Aborting : " + ex.Message, "ERROR",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error,
                                MessageBoxDefaultButton.Button1);
            }
            double percent = 0.0;

            if (img.Width >= width)
            {
                percent = calculation.percentageDecrease(img.Width, width);
            }
            else
            {
                percent = calculation.percentageIncrease(img.Width, width);
            }

            Size sz = calculation.increaseScale(img.Width, img.Height, percent);

            img = new Bitmap(img, new Size(width, height));
            return(flag);
        }
Ejemplo n.º 2
0
        private void start_processing()
        {
            int count = files.Length;
            int i     = 1;

            foreach (string file_load in files)
            {
                if (Path.GetExtension(file_load) == ".jpeg" || Path.GetExtension(file_load) == ".jpg" || Path.GetExtension(file_load) == ".JPG")
                {
                    SetText("Processing file " + file_load + "\n------------------------------------------\n");
                    if (status_lbl2.InvokeRequired)
                    {
                        status_lbl2.Invoke(new Action(() =>
                        {
                            status_lbl2.Text = "Processing File : " + i + " of " + count;
                        }));
                    }
                    else
                    {
                        status_lbl2.Text = "Processing File : " + i + " of " + count;
                    }
                    SetBitmap(file_load);

                    img = new Bitmap(file_load);



                    calculation = new calculation_class();
                    double percent = 0.0;
                    if (img.Width >= width)
                    {
                        percent = calculation.percentageDecrease(img.Width, width);
                    }
                    else
                    {
                        percent = calculation.percentageIncrease(img.Width, width);
                    }

                    Size sz = calculation.increaseScale(img.Width, img.Height, percent);
                    img = resizeImage((Image)img, sz.Width, sz.Height);
                    img = new Bitmap(img, new Size(width, height));

                    img = greyscale(img);


                    if (!fix_orientiation())
                    {
                        MessageBox.Show("Not Properly Aligned. Image Path : " + file_load);
                        continue;
                    }

                    file = file_load;

                    //img.Save(file_load+"PROCESSED"); // FOR DEBUGGING
                    findname();
                    findroll();
                    findresult();
                    name      = name.Trim();
                    questions = questions.Trim(new char[] { ',', ' ' });
                    if (roll == "")
                    {
                        roll = "00";
                    }
                    dt.Rows.Add(name,
                                roll, total, questions, options.Rows.Count * 5
                                );

                    name      = "";
                    roll      = "";
                    total     = 0;
                    questions = "";

                    img.Dispose();
                    i++;
                }
            }
            if (result_gridview.InvokeRequired)
            {
                result_gridview.Invoke(new Action(() =>
                {
                    result_gridview.DataSource = dt;
                    status_lbl2.Visible        = false;
                    result_gridview.Visible    = true;
                    result_gridview.Refresh();
                }));
            }
            else
            {
                result_gridview.DataSource = dt;
                status_lbl2.Visible        = false;
                result_gridview.Visible    = true;
                result_gridview.Refresh();
            }
            if (save_result_txt.InvokeRequired)
            {
                save_result_txt.Invoke(new Action(() =>
                {
                    save_result_txt.Visible = true;
                    save_result_btn.Visible = true;
                    csv_btn.Visible         = true;
                    reset_btn.Visible       = true;
                    status_lbl.Text         = "Processing Completed";
                }));
            }
            else
            {
                save_result_txt.Visible = true;
                save_result_btn.Visible = true;
                csv_btn.Visible         = true;
                reset_btn.Visible       = true;
                status_lbl.Text         = "Processing Completed";
            }
            //result_gridview.DataSource = dt;
        }