Пример #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);
            }
        }
Пример #2
0
        static SortedList <int, float> lfw_fe(string model, string net, string pair, string imgDir)
        {
            SortedList <int, float> results = new SortedList <int, float>();
            var          fe = new CaffeModel(net, model);
            StreamReader sr = new StreamReader(pair, Encoding.Default);
            string       line;
            int          label = 1;

            while ((line = sr.ReadLine()) != null)
            {
                string[] sArray = line.Split('\t');
                if (sArray.Length == 3)
                {
                    DirectoryInfo child      = new DirectoryInfo(imgDir + sArray[0]);
                    FileInfo[]    file       = child.GetFiles("*.jpg", SearchOption.AllDirectories);
                    float[]       a          = fe.ExtractFileOutputs(new[] { file[Convert.ToInt32(sArray[1]) - 1].FullName }, "eltmax_fc5", 0);
                    float[]       b          = fe.ExtractFileOutputs(new[] { file[Convert.ToInt32(sArray[2]) - 1].FullName }, "eltmax_fc5", 0);
                    float         confidency = CaffeModel.CosineDistanceProb(a, b);
                    results.Add(label, confidency);
                }
                if (sArray.Length == 4)
                {
                    DirectoryInfo child = new DirectoryInfo(imgDir + sArray[0]);
                    FileInfo[]    file  = child.GetFiles("*.jpg", SearchOption.AllDirectories);
                    float[]       a     = fe.ExtractFileOutputs(new[] { file[Convert.ToInt32(sArray[1]) - 1].FullName }, "eltmax_fc5", 0);
                    //
                    child = new DirectoryInfo(imgDir + sArray[2]);
                    file  = child.GetFiles("*.jpg", SearchOption.AllDirectories);
                    float[] b          = fe.ExtractFileOutputs(new[] { file[Convert.ToInt32(sArray[3]) - 1].FullName }, "eltmax_fc5", 0);
                    float   confidency = CaffeModel.CosineDistanceProb(a, b);
                    results.Add(-1 * label, confidency);
                }
                Console.WriteLine(label);
                label++;
            }
            return(results);
        }