Esempio n. 1
0
 /// <summary>
 /// Closes video writer.
 /// <para>Use dispose method to remove any additional resources.</para>
 /// </summary>
 public override void Close()
 {
     if (videoObjPtr != IntPtr.Zero)
     {
         CvHighGuiInvoke.cvReleaseVideoWriter(ref videoObjPtr);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Releases all resources allocated by capture.
 /// </summary>
 public override void Close()
 {
     if (capturePtr != IntPtr.Zero)
     {
         CvHighGuiInvoke.cvReleaseCapture(ref capturePtr);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Writes the provided image to the stream.
        /// </summary>
        /// <param name="image">Image to write.</param>
        /// <returns>True, if the operation was successful, false otherwise.</returns>
        protected unsafe override bool WriteInternal(IImage image)
        {
            bool isSuccessful;

            lock (syncObj)
            {
                if (image.ColorInfo.NumberOfChannels == 3 && !ColorFrames)
                {
                    throw new Exception("Image must be color!");
                }

                if (image.ColorInfo.NumberOfChannels == 1 && ColorFrames)
                {
                    throw new Exception("Image must be grayscale!");
                }

                if (!image.Size.Equals(FrameSize))
                {
                    throw new Exception("Input image must be the same size as defined frame size!");
                }

                this.Position++;

                var       iplImg    = image.AsOpenCvImage();
                IplImage *iplImgPtr = (IplImage *)&iplImg;

                isSuccessful = CvHighGuiInvoke.cvWriteFrame(videoObjPtr, (IntPtr)iplImgPtr);
            }

            return(isSuccessful);
        }
Esempio n. 4
0
 public static Size GetImageSize(IntPtr capturePtr)
 {
     return(new Size
     {
         Width = (int)CvHighGuiInvoke.cvGetCaptureProperty(capturePtr, CaptureProperty.FrameWidth),
         Height = (int)CvHighGuiInvoke.cvGetCaptureProperty(capturePtr, CaptureProperty.FrameHeight)
     });
 }
        /// <summary>
        /// Sets the position within the current stream.
        /// <para>Warning: the underlying OpenCV function seeks to nearest key-frame, therefore the seek operation may not be frame-accurate.</para>
        /// </summary>
        /// <param name="offset">A frame index offset relative to the origin parameter.</param>
        /// <param name="origin">A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.</param>
        /// <returns>The new position within the current stream.</returns>
        public override long Seek(long offset, System.IO.SeekOrigin origin = SeekOrigin.Current)
        {
            var frameIndex = base.Seek(offset, origin);

            CvHighGuiInvoke.cvSetCaptureProperty(capturePtr, CaptureProperty.PosFrames, frameIndex);

            return(Position);
        }
Esempio n. 6
0
        public static bool SetImageSize(IntPtr capturePtr, Size newSize)
        {
            bool success;

            success  = CvHighGuiInvoke.cvSetCaptureProperty(capturePtr, CaptureProperty.FrameWidth, newSize.Width);
            success &= CvHighGuiInvoke.cvSetCaptureProperty(capturePtr, CaptureProperty.FrameHeight, newSize.Height);

            return(success);
        }
Esempio n. 7
0
        /// <summary>
        /// Opens the camera stream.
        /// </summary>
        public override void Open()
        {
            if (capturePtr != IntPtr.Zero)
            {
                return;
            }

            capturePtr = CvHighGuiInvoke.cvCreateCameraCapture(cameraIdx);
            if (capturePtr == IntPtr.Zero)
            {
                throw new Exception("Cannot open camera stream! It seems that camera device can not be found.");
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Opens the video file stream.
        /// </summary>
        public override void Open()
        {
            if (videoObjPtr != IntPtr.Zero)
            {
                return;
            }

            videoObjPtr = CvHighGuiInvoke.cvCreateVideoWriter(OutputFileName, (int)Codec, FrameRate, FrameSize, ColorFrames);
            if (videoObjPtr == IntPtr.Zero)
            {
                throw new Exception(String.Format("Cannot open FileStream! Please check that the selected codec ({0}) is supported.", Codec));
            }
        }
        /// <summary>
        /// Opens the video file stream.
        /// </summary>
        public override void Open()
        {
            if (capturePtr != IntPtr.Zero)
            {
                return;
            }

            capturePtr = CvHighGuiInvoke.cvCreateFileCapture(fileName);
            if (capturePtr == IntPtr.Zero)
            {
                throw new Exception("Cannot open FileStream!");
            }
        }
        private static IImage cvLoader(string fileName)
        {
            var cvImg = CvHighGuiInvoke.cvLoadImage(fileName, ImageLoadType.Unchanged);
            var image = IplImage.FromPointer(cvImg).AsImage((_) =>
            {
                if (cvImg == IntPtr.Zero)
                {
                    return;
                }
                CvHighGuiInvoke.cvReleaseImage(ref cvImg);
            });

            return(image);
        }
Esempio n. 11
0
        /// <summary>
        /// Reads the next image in the stream and advances the position by one.
        /// </summary>
        /// <param name="image">Read image.</param>
        /// <returns>True if the reading operation was successful, false otherwise.</returns>
        protected override bool ReadInternal(out IImage image)
        {
            bool status = false;

            image = default(IImage);

            lock (syncObj)
            {
                IntPtr cvFramePtr;
                cvFramePtr = CvHighGuiInvoke.cvQueryFrame(capturePtr);

                if (cvFramePtr != IntPtr.Zero)
                {
                    image = IplImage.FromPointer(cvFramePtr).AsImage();
                    this.Position++;
                    status = true;
                }
            }

            return(status);
        }