private void getFrame(long offset)
        {
            saveCurrentAnnotations();

            capture.Seek(offset, SeekOrigin.Begin);
            loadCurrentImageAnnotations();
            GC.Collect();
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Reads the image source and save the extracted images to the specified folder.
        /// </summary>
        /// <param name="imageSource">Image stream reader.</param>
        /// <param name="outputDir">Output directory.</param>
        /// <param name="fileNameFormat">Image file name format.</param>
        /// <param name="onFrameCompletition">Progress function executed after a frame is saved.</param>
        public static void SaveFrames(this ImageStreamReader imageSource, string outputDir,
                                      string fileNameFormat = "img-{0:000}.png",
                                      Action <float> onFrameCompletition = null)
        {
            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }

            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
                }

                if (onFrameCompletition != null)
                {
                    onFrameCompletition((float)(idx + 1) / imageSource.Length);
                }

                idx++;
            }
        }
Пример #4
0
        void capture_NewFrame(object sender, EventArgs e)
        {
            reader.ReadTo <Bgr <byte> >(ref frame);

            if (frame == null)
            {
                /*Application.Idle -= capture_NewFrame;
                 * return;*/
                reader.Seek(0, SeekOrigin.Begin);
                return;
            }

            this.pictureBox.Image = frame.ToBitmap();
            GC.Collect();
        }
Пример #5
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));
                    frame.Convert <Bgr, byte>().ToBitmap().Save(path, imageQuality);
                }

                onFrameCompletition((float)(idx + 1) / imageSource.Length);
                idx++;
            }
        }
Пример #6
0
        void capture_NewFrame(object sender, EventArgs e)
        {
            reader.ReadTo <Bgr <byte> >(ref frame);

            if (frame == null)
            {
                /*Application.Idle -= capture_NewFrame;
                 * return;*/
                reader.Seek(0, SeekOrigin.Begin);
                return;
            }

            this.pictureBox.Image = frame.ToBitmap();

            //LINQ Grayscale conversion

            /*this.pictureBox.Image = frame.AsEnumerable()
             *                           .Select(x => x.ToGray())
             *                           .ToArray2D(frame.Size()).ToBitmap();*/
            GC.Collect();
        }
Пример #7
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++;
            }
        }
        void videoCapture_InitFrame(object sender, EventArgs e)
        {
            videoCapture.ReadTo(ref frame);
            if (frame == null)
            {
                return;
            }

            videoCapture.Seek(-1, SeekOrigin.Current);

            if (isROISelected)
            {
                initTracking(frame);
                Application.Idle -= videoCapture_InitFrame;
                Application.Idle += videoCapture_NewFrame;
            }
            else
            {
                frame.Draw(roi, Bgr <byte> .Blue, 3);
            }
            this.pictureBox.Image = frame.ToBitmap(); //it will be just casted (data is shared)

            GC.Collect();
        }
Пример #9
0
 /// <summary>
 /// Resets the enumerator,
 /// </summary>
 public void Reset()
 {
     streamableSource.Seek(0, SeekOrigin.Begin);
     position = -1;
 }