Ejemplo n.º 1
0
        void whatever()
        {
            string     net1   = @"IPBBox_deploy.prototxt";
            string     model1 = @"IPBBox_iter_iter_60000.caffemodel";
            CaffeModel IPBbox = new CaffeModel(net1, model1, false);

            string     net2   = @"5IPTs_deploy.prototxt";
            string     model2 = @"5IPTs_iter_iter_300000.caffemodel";
            CaffeModel IPTs5  = new CaffeModel(net2, model2, false);

            FastFace ff = new FastFace(1.1f, 3, 24);

            Bitmap bmp = new Bitmap(@"D:\小咖秀\20153月296月10\20170115150220800-315.jpg");


            FaceInfo info = ff.Facedetect_Multiview_Reinforce(bmp);

            //Bitmap[] bits = new Bitmap[info.count];
            Bitmap[]  bits    = new[] { bmp };
            Rectangle rect    = new Rectangle(0, 0, bmp.Width, bmp.Height);
            int       StartX  = Convert.ToInt32(rect.X - rect.Width * 0.2);
            int       StartY  = Convert.ToInt32(rect.Y - rect.Height * 0.2);
            int       iWidth  = Convert.ToInt32(rect.Width * 1.4);
            int       iHeight = Convert.ToInt32(rect.Height * 1.4);

            bits[0] = KiCut(bmp, StartX, StartY, iWidth, iHeight);
            for (int i = 0; i < info.count; i++)
            {
                //int StartX = Convert.ToInt32(info.r[i].X - info.r[i].Width * 0.2);
                //int StartY = Convert.ToInt32(info.r[i].Y - info.r[i].Height * 0.2);
                //int iWidth = Convert.ToInt32(info.r[i].Width * 1.4);
                //int iHeight = Convert.ToInt32(info.r[i].Height * 1.4);
                //bits[i] = KiCut(bmp, StartX, StartY, iWidth, iHeight);

                //Image<Bgr, byte> image = new Image<Bgr, byte>(bmp);
                //Rectangle rect = info.r[i];
                //rect.X = Convert.ToInt32(rect.X - rect.Width * 0.2);
                //rect.Y = Convert.ToInt32(rect.Y - rect.Height * 0.2);
                //rect.Width = Convert.ToInt32(rect.Width * 1.4);
                //rect.Height = Convert.ToInt32(rect.Height * 1.4);
                //image.ROI = rect;
                //bits[i] = image.Bitmap;
                //image.ROI = Rectangle.Empty; ;
            }
            if (/*info.count>0*/ true)
            {
                float[][]   aa    = IPBbox.ExtractBitmapOutputs(bits, new[] { "fc2", "fc3" }, 0);
                Rectangle[] rects = new Rectangle[info.count];
                Bitmap[]    C     = CaffeModel.Align_Step1(bits, rects, aa[0], aa[1]);

                float[]  bb = IPTs5.ExtractBitmapOutputs(C, "fc2", 0);
                Bitmap[] F  = CaffeModel.Align_Step2(bits, C, bb, rects, 128, 128);

                F[0].Save(@"C:\Users\BALTHASAR\Desktop\test.jpg");
                float[][] a =
                    IPBbox.ExtractFileOutputs(new[] { @"D:\Research\FacialLandmarks\Data\5PTS\batch1_1.jpg" },
                                              new[] { "fc2", "fc3" }, 0);
            }
        }
Ejemplo n.º 2
0
        static async void XiaoKaXiu()
        {
            string            model1            = @"IPBBox_iter_iter_60000.caffemodel";
            string            net1              = @"IPBBox_deploy.prototxt";
            string            model2            = @"5IPTs_iter_iter_300000.caffemodel";
            string            net2              = @"5IPTs_deploy.prototxt";
            var               IPBBox            = new CaffeModel(net1, model1, false);
            var               IPTs              = new CaffeModel(net2, model2, false);
            var               ff                = new FastFace(1.1f, 3, 48);
            string            fatherDir         = @"D:\CASIA\Cleaned_CASIA";
            FaceServiceClient faceServiceClient = new FaceServiceClient(SubscriptionKey);

            int count = 0;
            //Random rd=new Random(45985369);
            DirectoryInfo fatherInfo = new DirectoryInfo(fatherDir);

            DirectoryInfo[] childrenInfos = fatherInfo.GetDirectories();
            foreach (var childrenInfo in childrenInfos)
            {
                //DirectoryInfo[] SubInfos = childrenInfo.GetDirectories();

                FileInfo[] files = childrenInfo.GetFiles("*.jpg", SearchOption.AllDirectories);


                int filecounter = 0;
                foreach (var file in files)
                {
                    filecounter++;
                    try
                    {
                        if (count <= -1)
                        {
                            continue;
                        }
                        Bitmap   bmp  = new Bitmap(file.FullName);
                        FaceInfo info = ff.Facedetect_Frontal_Surveillance(bmp);
                        if (info.count != 1)
                        {
                            //Write("lost.txt", file.FullName);
                            continue;
                        }

                        ////**************
                        Bitmap[] bits = new Bitmap[1];
                        bits[0] = bmp;
                        Rectangle rect    = new Rectangle(0, 0, bmp.Width, bmp.Height);
                        int       StartX  = Convert.ToInt32(0 - bmp.Width * 0.2);
                        int       StartY  = Convert.ToInt32(0 - bmp.Height * 0.2);
                        int       iWidth  = Convert.ToInt32(bmp.Width * 1.4);
                        int       iHeight = Convert.ToInt32(bmp.Height * 1.4);
                        bits[0] = KiCut(bmp, StartX, StartY, iWidth, iHeight);

                        float[][] feature = IPBBox.ExtractBitmapOutputs(bits, new[] { "fc2", "fc3" }, 0);
                        if (Math.Abs(feature[1][0] * 90) >= 30)
                        {
                            bits[0].Dispose();
                            bmp.Dispose();
                            continue;
                        }

                        Rectangle[] rects = new Rectangle[bits.Length];
                        Bitmap[]    C     = CaffeModel.Align_Step1(bits, rects, feature[0], feature[1]);
                        float[]     bb    = IPTs.ExtractBitmapOutputs(C, "fc2", 0);
                        Bitmap[]    F     = CaffeModel.Align_Step2(bits, C, bb, rects, 128, 128);

                        if (!Directory.Exists(@"C:\Data\Alignment_CASIA\" + childrenInfo.Name))
                        {
                            Directory.CreateDirectory(@"C:\Data\Alignment_CASIA\" + childrenInfo.Name);
                        }
                        Image <Gray, byte> gray = new Image <Gray, byte>(F[0]);
                        //Image<Gray, byte> temp = gray.Resize(32, 32, Inter.Linear);
                        //temp = temp.Resize(64, 64, Inter.Linear);
                        gray._EqualizeHist();
                        Image <Bgr, byte> colorimg = new Image <Bgr, byte>(new Image <Gray, byte>[] { gray, gray, gray });
                        colorimg.Save(@"C:\Data\Alignment_CASIA\" + childrenInfo.Name + "\\" + filecounter + ".jpg");
                        //temp._EqualizeHist();
                        //temp.Save(@"C:\Data\Alignment_Registed_Equalized\" + childrenInfo.Name + "\\" + filecounter + "_per_blur.jpg");
                        //Console.WriteLine(@"C:\Data\Alignment_CASIA_Equalized\" + childrenInfo.Name + "\\" + filecounter + " complete!");
                        ////*****
                        colorimg.Dispose();
                        gray.Dispose();
                        F[0].Dispose();
                        C[0].Dispose();
                        bits[0].Dispose();
                        bmp.Dispose();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());

                        continue;
                        throw;
                    }

                    //}
                    //Console.WriteLine(filecounter);
                }
                Console.WriteLine(count);
                count++;
            }
        }