Example #1
0
 public ImageTemplate()
 {
     this.frame = new VideoFrame();
     info       = new Dictionary <string, object>();
 }
Example #2
0
 public ImageTemplate(VideoFrame frame)
     : this()
 {
     this.frame = frame;
 }
Example #3
0
        public static void ProcessTemplate(ImageTemplate template, bool extractKeypoints = true)
        {
            if (pyramid == null)
            {
                pyramid = new DeviceMemory <byte> [imgScales.Length];
                for (int i = 0; i < imgScales.Length; i++)
                {
                    double scaleFactor = 1.0 / Math.Pow(2, imgScales[i]);
                    int    height      = (int)Math.Ceiling((template.Image.Height * scaleFactor) / 4.0) * 4;
                    int    width       = (int)Math.Ceiling((template.Image.Width * scaleFactor) / 4.0) * 4;
                    pyramid[i] = worker.Malloc <byte>(width * height);
                }
            }

            template.Pyramid = new Image <Gray, byte> [imgScales.Length];
            List <float> texture = new List <float>();

            //List<float> variances = new List<float>();
            float[][] textureScales = new float[imgScales.Length][];

            //for (int i = 0; i < imgScales.Length; i++)
            Parallel.For(0, imgScales.Length, (int i) =>
            {
                double scaleFactor = 1.0 / Math.Pow(2, imgScales[i]);
                int height         = (int)Math.Ceiling((template.Image.Height * scaleFactor) / 4.0) * 4;
                int width          = (int)Math.Ceiling((template.Image.Width * scaleFactor) / 4.0) * 4;
                //int height = (int)(template.Image.Height * scaleFactor);
                //int width = (int)(template.Image.Width * scaleFactor);
                Image <Gray, byte> temp = new Image <Gray, byte>(width, height);
                CvInvoke.Resize(template.Image, temp, temp.Size);
                template.Pyramid[i] = temp;
                pyramid[i].Scatter(temp.Bytes);

                VideoFrame frame = new VideoFrame()
                {
                    Image = temp, ImageGPU = pyramid[i]
                };
                //float[] textureCurrentScale = AdaptiveLBP.GetInstance(temp.Size).GetHistogram(new VideoFrame() { Image = temp, ImageGPU = pyramid[i] });
                float[] textureCurrentScale = LBP.GetInstance(temp.Size).GetHistogram(frame);
                //float[] textureCurrentScale = Utils.ToFloat(Utils.Flatten(OldLBP.GetImageHistogramEfficient(temp)));
                //texture.AddRange(textureCurrentScale);
                textureScales[i] = textureCurrentScale;

                //variances.AddRange(LBP.GetInstance(temp.Size).GetVariances(frame));
            });
            foreach (float[] textureScale in textureScales)
            {
                texture.AddRange(textureScale);
            }
            template.Texture = texture.ToArray();
            //template["variances"] = variances;

            if (extractKeypoints)
            {
                GpuMat gpuImg      = new GpuMat(template.Image);
                GpuMat keypoints   = surf.DetectKeyPointsRaw(gpuImg);
                GpuMat descriptors = surf.ComputeDescriptorsRaw(gpuImg, null, keypoints);
                template.Keypoints = keypoints;
                VectorOfKeyPoint keypointVector = new VectorOfKeyPoint();
                surf.DownloadKeypoints(keypoints, keypointVector);
                template.KeypointVector = keypointVector;
                template.Descriptors    = descriptors;
            }
        }