예제 #1
0
 /// <summary>
 /// 识别图片中的文字
 /// </summary>
 /// <param name="image">图片</param>
 /// <param name="x">x偏移量</param>
 /// <param name="y">y偏移量</param>
 /// <returns></returns>
 public String getCharFromPic(Bitmap image, int x=0, int y=0)
 {
     this.subImgs = new List<Bitmap>();
     image.Save("xxx.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
     StringBuilder sb = new StringBuilder();
     ImageTool it = new ImageTool();
     it.setImage(image);
     it = it.changeToGrayImage().changeToBlackWhiteImage();
     if (minNearSpots != 0)
         it = it.removeBadBlock(1, 1, this.minNearSpots);
     for (int i = 0; i < this.offsetX.Length; i++)
     {
         Rectangle cloneRect = new Rectangle(this.offsetX[i]+x, this.offsetY+y, this.width, this.height);
         Bitmap subImg = it.Image.Clone(cloneRect, it.Image.PixelFormat);
         this.subImgs.Add(subImg);
         String s = OrcUtil.getSingleChar(subImg, this.dict);
         sb.Append(s);
     }
     return sb.ToString();
 }
예제 #2
0
파일: Form1.cs 프로젝트: CapricornZ/autobid
        private void button1_Click(object sender, EventArgs e)
        {
            FileStream fs = File.OpenRead("e:/cap.bmp");
            byte[] content = new byte[fs.Length];
            fs.Read(content, 0, (int)fs.Length);
            fs.Close();
            Bitmap bit = new Bitmap(new MemoryStream(content));
            Point point = ScreenUtil.scan(bit);

            Rectangle cloneRect = new Rectangle(point.X, point.Y, bit.Width-point.X, bit.Height-point.Y);
            Bitmap subImg = bit.Clone(cloneRect, bit.PixelFormat);
            this.pictureBox1.Image = subImg;
            subImg.Save("e:/capSub.bmp");

            ImageTool it = new ImageTool();
            it.setImage(bit);
            it.middleValueFilter(50, true).changeToGrayImage().changeToBlackWhiteImage().removeBadBlock(1, 1, 4);
            it.Image.Save("e:/capDone.bmp");

            Point start = new Point();
            for(int x=0; x<it.Image.Width; x++){
                int white = 0;
                for (int y = 0; y < it.Image.Height; y++)
                {
                    if (isWhite(it.Image.GetPixel(x, y)))
                        white++;
                }

                if (it.Image.Height - white > 1)
                {
                    start.X = x;
                    break;
                }
            }

            for (int y = 0; y < it.Image.Height; y++)
            {
                int white = 0;
                for (int x = start.X; x < 15; x++)
                {
                    if (isWhite(it.Image.GetPixel(x, y)))
                        white++;
                }
                Console.WriteLine("row:" + white);
            }
            //AllocConsole();
            //SetConsoleTitle("千万不要关掉我");
            //IntPtr windowHandle = FindWindow(null, System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
            //IntPtr closeMenu = GetSystemMenu(windowHandle, IntPtr.Zero);
            //uint SC_CLOSE = 0xF060;
            //RemoveMenu(closeMenu, SC_CLOSE, 0x0);

            //System.Diagnostics.Process process = System.Diagnostics.Process.Start("iexplore.exe", "http://moni.51hupai.org:8081");
            //System.Threading.Thread.Sleep(500);

            //IntPtr hTray = FindWindowA("IEFrame", null);
            //ShowWindow(hTray, 3);

            //this.webBrowser1.Navigate("http://moni.51hupai.org:8081");
        }