Exemple #1
0
        /// <summary>
        /// Extracts annotated samples - their bounding boxes.
        /// </summary>
        /// <param name="labelMatch">Regular expression for valid label.</param>
        private void extractPositives(Regex labelMatch)
        {
            if (database == null || capture == null || imageKeyFunc == null)
            {
                return; //form not initialized
            }
            var currPos = capture.Position;

            for (int i = 0; i < capture.Length; i++)
            {
                var imgKey = imageKeyFunc(i);
                if (database.ContainsKey(imgKey))
                {
                    capture.Seek(i, SeekOrigin.Begin);
                    var imgName = (capture as ImageDirectoryReader).CurrentImageName;
                    var img     = capture.Read();

                    var labelCounter = new Dictionary <string, int>();
                    foreach (var annotation in database[imgKey])
                    {
                        if (labelMatch.IsMatch(annotation.Label) == false)
                        {
                            continue;
                        }

                        //**************** get current label instance index ***************/
                        if (labelCounter.ContainsKey(annotation.Label) == false)
                        {
                            labelCounter.Add(annotation.Label, 0);
                        }

                        labelCounter[annotation.Label]++;

                        var label = annotation.Label;
                        if (labelCounter[annotation.Label] > 1)
                        {
                            label += " " + "(" + labelCounter[annotation.Label] + ")";
                        }
                        //**************** get current label instance index ***************/

                        var databaseDir = imgName.Replace(imgKey, String.Empty);
                        var samplePath  = getOutputImageName(databaseDir, imgKey, label);
                        Directory.CreateDirectory(Path.GetDirectoryName(samplePath));

                        var sampleImg = img.GetSubRect(annotation.BoundingRectangle);
                        //sampleImg = (sampleImg as Image<Bgr, byte>).SmoothGaussian(5);

                        ImageIO.TrySave(sampleImg, samplePath);
                    }
                }
            }

            capture.Seek(currPos, SeekOrigin.Begin);
        }
Exemple #2
0
        public void Start(Action <float> onFrameCompletition)
        {
            if (imageSource.CanSeek)
            {
                imageSource.Seek(0, SeekOrigin.Begin);
            }

            var idx = 0;

            foreach (var frame in imageSource) //use video stream as IEnumerable<IImage> (must support seek operation)
            {
                if (frame != null)             //some videos skip key frames (discard those frames)
                {
                    var path = Path.Combine(outputDir, String.Format(fileNameFormat, idx));
                    ImageIO.TrySave(frame, path); //TODO-noncritical: add compression options
                }

                onFrameCompletition((float)(idx + 1) / imageSource.Length);
                idx++;
            }
        }