Ejemplo n.º 1
0
        public void TestCutting()
        {
            var session = new WebSession();
            var buf     = session.GetRaw("https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png");
            var ms      = new MemoryStream(buf);
            var img     = (Bitmap)Image.FromStream(ms);
            var eff     = new EffImage(img);

            // 透明底rgb是0
            eff.ProcessEach((_, i, j) =>
            {
                var color = _.At(i, j);

                if (color.R == 0)
                {
                    _.Set(i, j, Color.White);
                }
            });

            eff.GrayScale();
            eff.AdativeBinarization();
            eff = EffImage.CutH(eff, 200, 330);
            eff = EffImage.CutV(eff, 100, 230);
            eff.Origin.Save("z:/cut.bmp");
        }
Ejemplo n.º 2
0
        public void TestOCR()
        {
            var img = new EffImage((Bitmap)Bitmap.FromFile("z:/test.jpg"));

            img.GrayScale();
            img.Binarization(100);
            img.Origin.Save("z:/test_bin.bmp");

            img = EffImage.Resize(img, 1024, 768);



            var vhist = img.ProjectionHistV();

            // 用垂直投影找底部
            var bottom     = img.Bottom;
            int upperBound = 0;

            for (upperBound = bottom; upperBound > 0; upperBound--)
            {
                if (vhist[upperBound] <= 5)
                {
                    break;
                }
            }

            var idImg = EffImage.CutV(img, upperBound, bottom);

            idImg.ClearNoise(3);

            idImg.Binarization(50);
            var area = idImg.ConnectedAreas;
            int i    = 0;

            foreach (var item in area)
            {
                var rect = item.ValidArea;
                var seg  = EffImage.CutH(EffImage.CutV(idImg, rect.Top, rect.Bottom), rect.Left, rect.Right);
                var resz = EffImage.Resize(seg, 32, 32);
                resz.Origin.Save($"z:/seg/{i++}.bmp");
            }
        }