Beispiel #1
0
        private void  择一幅图像截取字保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Bitmap bit = new Bitmap(pathImageFiles1[0]); //这是选择的那幅图像

            for (int i = 0; i < 100; i++)                //识别出的文字数量,如100个
            {
                Rectangle rect    = new Rectangle();     //这个是要截取的内容区域。是有确定的值。
                Bitmap    bitSave = ImageDealClass.getPositionImage(bit, rect);
                bitSave.Save(@"C:\Users\zbx\Desktop\" + i + ".png", System.Drawing.Imaging.ImageFormat.Png);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 相似度测试 包括相似度识别和生成图片报告
        /// </summary>
        private void xiangsiduTest2()
        {
            string pathOld = pathFolder1;
            string pathNew = pathFolder2;

            string[] filePath    = Directory.GetFiles(pathOld).OrderBy(x => x.Length).ThenBy(x => x).ToArray();
            string[] filePathNew = Directory.GetFiles(pathNew).OrderBy(x => x.Length).ThenBy(x => x).ToArray();
            //新建一张图,在图上绘制报告图
            Bitmap   bit = new Bitmap(1800, 3000);
            Graphics g   = Graphics.FromImage(bit);

            g.FillRectangle(Brushes.White, new Rectangle(0, 0, 1800, 3000));
            SolidBrush drawBrush = new SolidBrush(Color.Black);

            //初始化进度条
            if (toolStripProgressBar1.Value != 0)
            {
                toolStripProgressBar1.Value = 0;
            }
            toolStripProgressBar1.Maximum = filePath.Length;
            int    mistake = 0;//计数:超过15阈值的计数
            double percent = 0;

            for (int i = 0; i < filePath.Length; i++)
            {
                Image <Bgr, Byte> imgOld = new Image <Bgr, Byte>(filePath[i]);
                Image <Bgr, Byte> imgNew = new Image <Bgr, Byte>(filePathNew[i]);

                int    x          = i / 100; //如果超过一百条,则在横坐标150位置继续画。 一段长度占150.假设能共有1200个字。要12行。长度总为12*150=1800.垂直需要100*30=3000;
                int    y          = i % 100;
                PointF drawPoint0 = new PointF(0 + x * 150, y * 30);
                PointF drawPoint1 = new PointF(30 + x * 150, y * 30);
                PointF drawPoint2 = new PointF(70 + x * 150, y * 30);
                PointF drawPoint3 = new PointF(110 + x * 150, y * 30);
                Font   drawFont0  = new Font("宋体", 10, FontStyle.Regular);
                Font   drawFont   = new Font("宋体", 16, FontStyle.Regular);
                g.DrawString(Path.GetFileNameWithoutExtension(filePath[i]), drawFont0, drawBrush, drawPoint0);//把字体画出来
                g.DrawImage(imgOld.ToBitmap(), drawPoint1);
                g.DrawImage(imgNew.ToBitmap(), drawPoint2);
                int diffNum = ImageDealClass.getHashDiff(imgOld, imgNew);
                if (diffNum > 15)
                {
                    mistake++;
                }
                g.DrawString(diffNum.ToString(), drawFont, drawBrush, drawPoint3);//把差异数画到坐标
                toolStripProgressBar1.Value++;
            }
            percent = Convert.ToDouble(mistake) / filePath.Length * 100;

            bit.Save(@"C:\Users\zbx\Desktop\结果.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            MessageBox.Show(@"生成图片位于:C:\Users\zbx\Desktop\结果.jpg" + "超出的共有" + mistake + "" + "占百分比为:" + percent);
        }
Beispiel #3
0
        /// <summary>
        /// 相似度测试 包括相似度识别和生成图片报告
        /// </summary>
        private void xiangsiduTest()
        {
            string pathOld = pathFolder1;
            string pathNew = pathFolder2;

            string[] filePath    = Directory.GetFiles(pathOld).OrderBy(x => x.Length).ThenBy(x => x).ToArray();
            string[] filePathNew = Directory.GetFiles(pathNew).OrderBy(x => x.Length).ThenBy(x => x).ToArray();
            //新建一张图,在图上绘制报告图
            Bitmap   bit = new Bitmap(290, 4380);
            Graphics g   = Graphics.FromImage(bit);

            g.FillRectangle(Brushes.White, new Rectangle(0, 0, 290, 4380));
            SolidBrush drawBrush = new SolidBrush(Color.Black);

            //初始化进度条
            if (toolStripProgressBar1.Value != 0)
            {
                toolStripProgressBar1.Value = 0;
            }
            toolStripProgressBar1.Maximum = filePath.Length;

            for (int i = 0; i < filePath.Length; i++)
            {
                Image <Bgr, Byte> imgOld     = new Image <Bgr, Byte>(filePath[i]);
                Image <Bgr, Byte> imgNew     = new Image <Bgr, Byte>(filePathNew[i]);
                PointF            drawPoint0 = new PointF(0, i * 30);   //图0放在0,0位置画30*30大小 这个画字体
                PointF            drawPoint1 = new PointF(200, i * 30); //图1放在30,0位置画30*30大小
                PointF            drawPoint2 = new PointF(230, i * 30); //图2放在60,0位置画30*30大小
                PointF            drawPoint3 = new PointF(260, i * 30); //图3放在90,0位置画30*30大小
                Font drawFont0 = new Font("宋体", 10, FontStyle.Regular);
                Font drawFont  = new Font("宋体", 16, FontStyle.Regular);
                g.DrawString(Path.GetFileNameWithoutExtension(filePath[i]), drawFont0, drawBrush, drawPoint0);//把字体画出来
                g.DrawImage(imgOld.ToBitmap(), drawPoint1);
                g.DrawImage(imgNew.ToBitmap(), drawPoint2);
                int diffNum = ImageDealClass.getHashDiff(imgOld, imgNew);
                g.DrawString(diffNum.ToString(), drawFont, drawBrush, drawPoint3);//把差异数画到坐标
                toolStripProgressBar1.Value++;
            }

            bit.Save(@"C:\Users\zbx\Desktop\结果.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            MessageBox.Show(@"生成图片位于:C:\Users\zbx\Desktop\结果.jpg");
        }
Beispiel #4
0
        private void 裁掉空白ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //在原路径建立同名加new的文件夹存储处理后的图片
            string direName = Path.GetDirectoryName(pathImageFiles1[0]) + "new";

            Directory.CreateDirectory(direName);

            for (int i = 0; i < pathImageFiles1.Length; i++)
            {
                Bitmap bit            = new Bitmap(pathImageFiles1[i]);
                Bitmap gray           = ImageDealClass.huiduhua(bit);
                Bitmap thresholdImage = ImageDealClass.getez(gray);

                int x, y, width, height;
                ImageDealClass.FindPicContent(thresholdImage, out x, out y, out width, out height);
                Bitmap    bitSave        = new Bitmap(width, height);          //要保存的大小
                Graphics  g              = Graphics.FromImage(bitSave);
                Rectangle rect1          = new Rectangle(x, y, width, height); //原图的哪个部分哪个大小拿来绘制
                Rectangle destRectangle2 = new Rectangle(0, 0, width, height); // 在新图上什么位置开始绘制什么大小
                g.DrawImage(thresholdImage, destRectangle2, rect1, GraphicsUnit.Pixel);
                bitSave.Save(direName + "\\" + Path.GetFileName(pathImageFiles1[i]));
            } //for
            MessageBox.Show("ok");
        }     //private