Пример #1
0
 /// <summary>
 /// Method for creating a nice red highlighting rectangle above the cell under cursor
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
 {
     try
     {
         Point cellCoords = BitmapCoordsToCellCoords(PicBoxCoordsToBitmapCoords(e.Location));
         if (cellCoords == m_lastCellCoords)
         {
             return;
         }
         var cellRectangle =
             OcrReader.GetCellCoordinates(m_hLines, m_vLines, cellCoords.X, cellCoords.Y).ToRectangle();
         if (!m_lastCellRectangle.IsEmpty)
         {
             var b = pictureBox1.Image as Bitmap;
             for (int y = m_lastCellRectangle.Top; y < m_lastCellRectangle.Bottom; y++)
             {
                 for (int x = m_lastCellRectangle.Left; x < m_lastCellRectangle.Right; x++)
                 {
                     Debug.Assert(b != null, "b != null");
                     b.SetPixel(x, y, m_picture.GetPixel(x, y));
                 }
             }
         }
         m_lastCellRectangle = cellRectangle;
         m_lastCellCoords    = cellCoords;
         Graphics g = Graphics.FromImage(pictureBox1.Image);
         g.FillRectangle(new SolidBrush(Color.FromArgb(50, 255, 0, 0)), cellRectangle);
         pictureBox1.Refresh();
     } catch {}
 }
Пример #2
0
        /// <summary>
        /// Returns a list of filled cells.
        /// Lists through every cell and if at least 1% is non-white, the cell is considered to be non-empty.
        /// </summary>
        /// <returns></returns>
        private List <MyRectangle> FindFilledCells()
        {
            Color penColor            = m_picture.GetPixel(0, 0); // Get color of pen using which the numbers are written
            List <MyRectangle> result = new List <MyRectangle>();

            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    Rectangle cell = OcrReader.GetCellCoordinates(m_hLines, m_vLines, x, y).ToRectangle();
                    int       numOfPixelsFilled = 0;
                    for (int i = cell.Left; i < cell.Right; i++)
                    {
                        for (int j = cell.Top; j < cell.Bottom; j++)
                        {
                            if (m_picture.GetPixel(i, j).Equals(penColor))
                            {
                                numOfPixelsFilled++;
                            }
                        }
                    }
                    // If at least 1% is filled
                    if (numOfPixelsFilled > NUM_OF_PERCENT_FILLED * (cell.Width * cell.Height))
                    {
                        // Test of correctness

                        /*Graphics g = Graphics.FromImage(pictureBox1.Image);
                         * g.DrawRectangle(new Pen(Color.Red, 3), cell);
                         * pictureBox1.Refresh();
                         * Application.DoEvents();*/
                        result.Add(new MyRectangle(cell, x, y));
                    }
                }
            }
            //pictureBox1.Refresh();
            return(result);
        }