10 .. ocv:class:: gpu::BroxOpticalFlow
12 Class computing the optical flow for two images using Brox et al Optical Flow algorithm ([Brox2004]_). ::
17 BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_);
19 //! Compute optical flow
20 //! frame0 - source frame (supports only CV_32FC1 type)
21 //! frame1 - frame to track (with the same size and type as frame0)
22 //! u - flow horizontal component (along x axis)
23 //! v - flow vertical component (along y axis)
24 void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null());
29 //! gradient constancy importance
32 //! pyramid scale factor
35 //! number of lagged non-linearity iterations (inner loop)
38 //! number of warping iterations (number of pyramid levels)
41 //! number of linear system solver iterations
42 int solver_iterations;
49 gpu::GoodFeaturesToTrackDetector_GPU
50 ------------------------------------
51 .. ocv:class:: gpu::GoodFeaturesToTrackDetector_GPU
53 Class used for strong corners detection on an image. ::
55 class GoodFeaturesToTrackDetector_GPU
58 explicit GoodFeaturesToTrackDetector_GPU(int maxCorners_ = 1000, double qualityLevel_ = 0.01, double minDistance_ = 0.0,
59 int blockSize_ = 3, bool useHarrisDetector_ = false, double harrisK_ = 0.04);
61 void operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat());
68 bool useHarrisDetector;
74 The class finds the most prominent corners in the image.
76 .. seealso:: :ocv:func:`goodFeaturesToTrack`
80 gpu::GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU
81 ---------------------------------------------------------------------
84 .. ocv:function:: gpu::GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0, int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04)
86 :param maxCorners: Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned.
88 :param qualityLevel: Parameter characterizing the minimal accepted quality of image corners. The parameter value is multiplied by the best corner quality measure, which is the minimal eigenvalue (see :ocv:func:`gpu::cornerMinEigenVal` ) or the Harris function response (see :ocv:func:`gpu::cornerHarris` ). The corners with the quality measure less than the product are rejected. For example, if the best corner has the quality measure = 1500, and the ``qualityLevel=0.01`` , then all the corners with the quality measure less than 15 are rejected.
90 :param minDistance: Minimum possible Euclidean distance between the returned corners.
92 :param blockSize: Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. See :ocv:func:`cornerEigenValsAndVecs` .
94 :param useHarrisDetector: Parameter indicating whether to use a Harris detector (see :ocv:func:`gpu::cornerHarris`) or :ocv:func:`gpu::cornerMinEigenVal`.
96 :param harrisK: Free parameter of the Harris detector.
100 gpu::GoodFeaturesToTrackDetector_GPU::operator ()
101 -------------------------------------------------
102 Finds the most prominent corners in the image.
104 .. ocv:function:: void gpu::GoodFeaturesToTrackDetector_GPU::operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat())
106 :param image: Input 8-bit, single-channel image.
108 :param corners: Output vector of detected corners (it will be one row matrix with CV_32FC2 type).
110 :param mask: Optional region of interest. If the image is not empty (it needs to have the type ``CV_8UC1`` and the same size as ``image`` ), it specifies the region in which the corners are detected.
112 .. seealso:: :ocv:func:`goodFeaturesToTrack`
116 gpu::GoodFeaturesToTrackDetector_GPU::releaseMemory
117 ---------------------------------------------------
118 Releases inner buffers memory.
120 .. ocv:function:: void gpu::GoodFeaturesToTrackDetector_GPU::releaseMemory()
124 gpu::FarnebackOpticalFlow
125 -------------------------
126 .. ocv:class:: gpu::FarnebackOpticalFlow
128 Class computing a dense optical flow using the Gunnar Farneback’s algorithm. ::
130 class CV_EXPORTS FarnebackOpticalFlow
133 FarnebackOpticalFlow()
137 fastPyramids = false;
154 void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null());
156 void releaseMemory();
164 gpu::FarnebackOpticalFlow::operator ()
165 --------------------------------------
166 Computes a dense optical flow using the Gunnar Farneback’s algorithm.
168 .. ocv:function:: void gpu::FarnebackOpticalFlow::operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null())
170 :param frame0: First 8-bit gray-scale input image
171 :param frame1: Second 8-bit gray-scale input image
172 :param flowx: Flow horizontal component
173 :param flowy: Flow vertical component
176 .. seealso:: :ocv:func:`calcOpticalFlowFarneback`
180 gpu::FarnebackOpticalFlow::releaseMemory
181 ----------------------------------------
182 Releases unused auxiliary memory buffers.
184 .. ocv:function:: void gpu::FarnebackOpticalFlow::releaseMemory()
188 gpu::PyrLKOpticalFlow
189 ---------------------
190 .. ocv:class:: gpu::PyrLKOpticalFlow
192 Class used for calculating an optical flow. ::
194 class PyrLKOpticalFlow
199 void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts,
200 GpuMat& status, GpuMat* err = 0);
202 void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0);
209 void releaseMemory();
212 The class can calculate an optical flow for a sparse feature set or dense optical flow using the iterative Lucas-Kanade method with pyramids.
214 .. seealso:: :ocv:func:`calcOpticalFlowPyrLK`
218 gpu::PyrLKOpticalFlow::sparse
219 -----------------------------
220 Calculate an optical flow for a sparse feature set.
222 .. ocv:function:: void gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, GpuMat& status, GpuMat* err = 0)
224 :param prevImg: First 8-bit input image (supports both grayscale and color images).
226 :param nextImg: Second input image of the same size and the same type as ``prevImg`` .
228 :param prevPts: Vector of 2D points for which the flow needs to be found. It must be one row matrix with CV_32FC2 type.
230 :param nextPts: Output vector of 2D points (with single-precision floating-point coordinates) containing the calculated new positions of input features in the second image. When ``useInitialFlow`` is true, the vector must have the same size as in the input.
232 :param status: Output status vector (CV_8UC1 type). Each element of the vector is set to 1 if the flow for the corresponding features has been found. Otherwise, it is set to 0.
234 :param err: Output vector (CV_32FC1 type) that contains the difference between patches around the original and moved points or min eigen value if ``getMinEigenVals`` is checked. It can be NULL, if not needed.
236 .. seealso:: :ocv:func:`calcOpticalFlowPyrLK`
240 gpu::PyrLKOpticalFlow::dense
241 -----------------------------
242 Calculate dense optical flow.
244 .. ocv:function:: void gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0)
246 :param prevImg: First 8-bit grayscale input image.
248 :param nextImg: Second input image of the same size and the same type as ``prevImg`` .
250 :param u: Horizontal component of the optical flow of the same size as input images, 32-bit floating-point, single-channel
252 :param v: Vertical component of the optical flow of the same size as input images, 32-bit floating-point, single-channel
254 :param err: Output vector (CV_32FC1 type) that contains the difference between patches around the original and moved points or min eigen value if ``getMinEigenVals`` is checked. It can be NULL, if not needed.
258 gpu::PyrLKOpticalFlow::releaseMemory
259 ------------------------------------
260 Releases inner buffers memory.
262 .. ocv:function:: void gpu::PyrLKOpticalFlow::releaseMemory()
266 gpu::interpolateFrames
267 ----------------------
268 Interpolates frames (images) using provided optical flow (displacement field).
270 .. ocv:function:: void gpu::interpolateFrames(const GpuMat& frame0, const GpuMat& frame1, const GpuMat& fu, const GpuMat& fv, const GpuMat& bu, const GpuMat& bv, float pos, GpuMat& newFrame, GpuMat& buf, Stream& stream = Stream::Null())
272 :param frame0: First frame (32-bit floating point images, single channel).
274 :param frame1: Second frame. Must have the same type and size as ``frame0`` .
276 :param fu: Forward horizontal displacement.
278 :param fv: Forward vertical displacement.
280 :param bu: Backward horizontal displacement.
282 :param bv: Backward vertical displacement.
284 :param pos: New frame position.
286 :param newFrame: Output image.
288 :param buf: Temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat: occlusion masks for first frame, occlusion masks for second, interpolated forward horizontal flow, interpolated forward vertical flow, interpolated backward horizontal flow, interpolated backward vertical flow.
290 :param stream: Stream for the asynchronous version.
296 .. ocv:class:: gpu::FGDStatModel
298 Class used for background/foreground segmentation. ::
308 explicit FGDStatModel(int out_cn = 3);
309 explicit FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3);
313 void create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params());
316 int update(const cv::gpu::GpuMat& curFrame);
318 //8UC3 or 8UC4 reference background image
319 cv::gpu::GpuMat background;
321 //8UC1 foreground image
322 cv::gpu::GpuMat foreground;
324 std::vector< std::vector<cv::Point> > foreground_regions;
327 The class discriminates between foreground and background pixels by building and maintaining a model of the background. Any pixel which does not fit this model is then deemed to be foreground. The class implements algorithm described in [FGD2003]_.
329 The results are available through the class fields:
331 .. ocv:member:: cv::gpu::GpuMat background
333 The output background image.
335 .. ocv:member:: cv::gpu::GpuMat foreground
337 The output foreground mask as an 8-bit binary image.
339 .. ocv:member:: cv::gpu::GpuMat foreground_regions
341 The output foreground regions calculated by :ocv:func:`findContours`.
345 gpu::FGDStatModel::FGDStatModel
346 -------------------------------
349 .. ocv:function:: gpu::FGDStatModel::FGDStatModel(int out_cn = 3)
350 .. ocv:function:: gpu::FGDStatModel::FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3)
352 :param firstFrame: First frame from video stream. Supports 3- and 4-channels input ( ``CV_8UC3`` and ``CV_8UC4`` ).
354 :param params: Algorithm's parameters. See [FGD2003]_ for explanation.
356 :param out_cn: Channels count in output result and inner buffers. Can be 3 or 4. 4-channels version requires more memory, but works a bit faster.
358 .. seealso:: :ocv:func:`gpu::FGDStatModel::create`
362 gpu::FGDStatModel::create
363 -------------------------
364 Initializes background model.
366 .. ocv:function:: void gpu::FGDStatModel::create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params())
368 :param firstFrame: First frame from video stream. Supports 3- and 4-channels input ( ``CV_8UC3`` and ``CV_8UC4`` ).
370 :param params: Algorithm's parameters. See [FGD2003]_ for explanation.
374 gpu::FGDStatModel::release
375 --------------------------
376 Releases all inner buffer's memory.
378 .. ocv:function:: void gpu::FGDStatModel::release()
382 gpu::FGDStatModel::update
383 --------------------------
384 Updates the background model and returns foreground regions count.
386 .. ocv:function:: int gpu::FGDStatModel::update(const cv::gpu::GpuMat& curFrame)
388 :param curFrame: Next video frame.
394 .. ocv:class:: gpu::MOG_GPU
396 Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm. ::
401 MOG_GPU(int nmixtures = -1);
403 void initialize(Size frameSize, int frameType);
405 void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null());
407 void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
413 float backgroundRatio;
417 The class discriminates between foreground and background pixels by building and maintaining a model of the background. Any pixel which does not fit this model is then deemed to be foreground. The class implements algorithm described in [MOG2001]_.
419 .. seealso:: :ocv:class:`BackgroundSubtractorMOG`
423 gpu::MOG_GPU::MOG_GPU
424 ---------------------
427 .. ocv:function:: gpu::MOG_GPU::MOG_GPU(int nmixtures = -1)
429 :param nmixtures: Number of Gaussian mixtures.
431 Default constructor sets all parameters to default values.
435 gpu::MOG_GPU::operator()
436 ------------------------
437 Updates the background model and returns the foreground mask.
439 .. ocv:function:: void gpu::MOG_GPU::operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null())
441 :param frame: Next video frame.
443 :param fgmask: The output foreground mask as an 8-bit binary image.
445 :param stream: Stream for the asynchronous version.
449 gpu::MOG_GPU::getBackgroundImage
450 --------------------------------
451 Computes a background image.
453 .. ocv:function:: void gpu::MOG_GPU::getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const
455 :param backgroundImage: The output background image.
457 :param stream: Stream for the asynchronous version.
461 gpu::MOG_GPU::release
462 ---------------------
463 Releases all inner buffer's memory.
465 .. ocv:function:: void gpu::MOG_GPU::release()
471 .. ocv:class:: gpu::MOG2_GPU
473 Gaussian Mixture-based Background/Foreground Segmentation Algorithm. ::
478 MOG2_GPU(int nmixtures = -1);
480 void initialize(Size frameSize, int frameType);
482 void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null());
484 void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
492 The class discriminates between foreground and background pixels by building and maintaining a model of the background. Any pixel which does not fit this model is then deemed to be foreground. The class implements algorithm described in [MOG2004]_.
494 Here are important members of the class that control the algorithm, which you can set after constructing the class instance:
496 .. ocv:member:: float backgroundRatio
498 Threshold defining whether the component is significant enough to be included into the background model ( corresponds to ``TB=1-cf`` from the paper??which paper??). ``cf=0.1 => TB=0.9`` is default. For ``alpha=0.001``, it means that the mode should exist for approximately 105 frames before it is considered foreground.
500 .. ocv:member:: float varThreshold
502 Threshold for the squared Mahalanobis distance that helps decide when a sample is close to the existing components (corresponds to ``Tg``). If it is not close to any component, a new component is generated. ``3 sigma => Tg=3*3=9`` is default. A smaller ``Tg`` value generates more components. A higher ``Tg`` value may result in a small number of components but they can grow too large.
504 .. ocv:member:: float fVarInit
506 Initial variance for the newly generated components. It affects the speed of adaptation. The parameter value is based on your estimate of the typical standard deviation from the images. OpenCV uses 15 as a reasonable value.
508 .. ocv:member:: float fVarMin
510 Parameter used to further control the variance.
512 .. ocv:member:: float fVarMax
514 Parameter used to further control the variance.
516 .. ocv:member:: float fCT
518 Complexity reduction parameter. This parameter defines the number of samples needed to accept to prove the component exists. ``CT=0.05`` is a default value for all the samples. By setting ``CT=0`` you get an algorithm very similar to the standard Stauffer&Grimson algorithm.
520 .. ocv:member:: uchar nShadowDetection
522 The value for marking shadow pixels in the output foreground mask. Default value is 127.
524 .. ocv:member:: float fTau
526 Shadow threshold. The shadow is detected if the pixel is a darker version of the background. ``Tau`` is a threshold defining how much darker the shadow can be. ``Tau= 0.5`` means that if a pixel is more than twice darker then it is not shadow. See [ShadowDetect2003]_.
528 .. ocv:member:: bool bShadowDetection
530 Parameter defining whether shadow detection should be enabled.
532 .. seealso:: :ocv:class:`BackgroundSubtractorMOG2`
536 gpu::MOG2_GPU::MOG2_GPU
537 -----------------------
540 .. ocv:function:: gpu::MOG2_GPU::MOG2_GPU(int nmixtures = -1)
542 :param nmixtures: Number of Gaussian mixtures.
544 Default constructor sets all parameters to default values.
548 gpu::MOG2_GPU::operator()
549 -------------------------
550 Updates the background model and returns the foreground mask.
552 .. ocv:function:: void gpu::MOG2_GPU::operator()( const GpuMat& frame, GpuMat& fgmask, float learningRate=-1.0f, Stream& stream=Stream::Null() )
554 :param frame: Next video frame.
556 :param fgmask: The output foreground mask as an 8-bit binary image.
558 :param stream: Stream for the asynchronous version.
562 gpu::MOG2_GPU::getBackgroundImage
563 ---------------------------------
564 Computes a background image.
566 .. ocv:function:: void gpu::MOG2_GPU::getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const
568 :param backgroundImage: The output background image.
570 :param stream: Stream for the asynchronous version.
574 gpu::MOG2_GPU::release
575 ----------------------
576 Releases all inner buffer's memory.
578 .. ocv:function:: void gpu::MOG2_GPU::release()
584 .. ocv:class:: gpu::GMG_GPU
586 Class used for background/foreground segmentation. ::
593 void initialize(Size frameSize, float min = 0.0f, float max = 255.0f);
595 void operator ()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null());
601 int numInitializationFrames;
602 int quantizationLevels;
603 float backgroundPrior;
604 float decisionThreshold;
610 The class discriminates between foreground and background pixels by building and maintaining a model of the background. Any pixel which does not fit this model is then deemed to be foreground. The class implements algorithm described in [GMG2012]_.
612 Here are important members of the class that control the algorithm, which you can set after constructing the class instance:
614 .. ocv:member:: int maxFeatures
616 Total number of distinct colors to maintain in histogram.
618 .. ocv:member:: float learningRate
620 Set between 0.0 and 1.0, determines how quickly features are "forgotten" from histograms.
622 .. ocv:member:: int numInitializationFrames
624 Number of frames of video to use to initialize histograms.
626 .. ocv:member:: int quantizationLevels
628 Number of discrete levels in each channel to be used in histograms.
630 .. ocv:member:: float backgroundPrior
632 Prior probability that any given pixel is a background pixel. A sensitivity parameter.
634 .. ocv:member:: float decisionThreshold
636 Value above which pixel is determined to be FG.
638 .. ocv:member:: float smoothingRadius
640 Smoothing radius, in pixels, for cleaning up FG image.
644 gpu::GMG_GPU::GMG_GPU
645 ---------------------
646 The default constructor.
648 .. ocv:function:: gpu::GMG_GPU::GMG_GPU()
650 Default constructor sets all parameters to default values.
654 gpu::GMG_GPU::initialize
655 ------------------------
656 Initialize background model and allocates all inner buffers.
658 .. ocv:function:: void gpu::GMG_GPU::initialize(Size frameSize, float min = 0.0f, float max = 255.0f)
660 :param frameSize: Input frame size.
662 :param min: Minimum value taken on by pixels in image sequence. Usually 0.
664 :param max: Maximum value taken on by pixels in image sequence, e.g. 1.0 or 255.
668 gpu::GMG_GPU::operator()
669 ------------------------
670 Updates the background model and returns the foreground mask
672 .. ocv:function:: void gpu::GMG_GPU::operator ()( const GpuMat& frame, GpuMat& fgmask, float learningRate=-1.0f, Stream& stream=Stream::Null() )
674 :param frame: Next video frame.
676 :param fgmask: The output foreground mask as an 8-bit binary image.
678 :param stream: Stream for the asynchronous version.
682 gpu::GMG_GPU::release
683 ---------------------
684 Releases all inner buffer's memory.
686 .. ocv:function:: void gpu::GMG_GPU::release()
691 ---------------------
694 .. ocv:class:: gpu::VideoWriter_GPU
696 The class uses H264 video codec.
698 .. note:: Currently only Windows platform is supported.
702 gpu::VideoWriter_GPU::VideoWriter_GPU
703 -------------------------------------
706 .. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU()
707 .. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR)
708 .. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR)
709 .. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR)
710 .. ocv:function:: gpu::VideoWriter_GPU::VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR)
712 :param fileName: Name of the output video file. Only AVI file format is supported.
714 :param frameSize: Size of the input video frames.
716 :param fps: Framerate of the created video stream.
718 :param params: Encoder parameters. See :ocv:struct:`gpu::VideoWriter_GPU::EncoderParams` .
720 :param format: Surface format of input frames ( ``SF_UYVY`` , ``SF_YUY2`` , ``SF_YV12`` , ``SF_NV12`` , ``SF_IYUV`` , ``SF_BGR`` or ``SF_GRAY``). BGR or gray frames will be converted to YV12 format before encoding, frames with other formats will be used as is.
722 :param encoderCallback: Callbacks for video encoder. See :ocv:class:`gpu::VideoWriter_GPU::EncoderCallBack` . Use it if you want to work with raw video stream.
724 The constructors initialize video writer. FFMPEG is used to write videos. User can implement own multiplexing with :ocv:class:`gpu::VideoWriter_GPU::EncoderCallBack` .
728 gpu::VideoWriter_GPU::open
729 --------------------------
730 Initializes or reinitializes video writer.
732 .. ocv:function:: void gpu::VideoWriter_GPU::open(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR)
733 .. ocv:function:: void gpu::VideoWriter_GPU::open(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR)
734 .. ocv:function:: void gpu::VideoWriter_GPU::open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR)
735 .. ocv:function:: void gpu::VideoWriter_GPU::open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR)
737 The method opens video writer. Parameters are the same as in the constructor :ocv:func:`gpu::VideoWriter_GPU::VideoWriter_GPU` . The method throws :ocv:class:`Exception` if error occurs.
741 gpu::VideoWriter_GPU::isOpened
742 ------------------------------
743 Returns true if video writer has been successfully initialized.
745 .. ocv:function:: bool gpu::VideoWriter_GPU::isOpened() const
749 gpu::VideoWriter_GPU::close
750 ---------------------------
751 Releases the video writer.
753 .. ocv:function:: void gpu::VideoWriter_GPU::close()
757 gpu::VideoWriter_GPU::write
758 ---------------------------
759 Writes the next video frame.
761 .. ocv:function:: void gpu::VideoWriter_GPU::write(const cv::gpu::GpuMat& image, bool lastFrame = false)
763 :param image: The written frame.
765 :param lastFrame: Indicates that it is end of stream. The parameter can be ignored.
767 The method write the specified image to video file. The image must have the same size and the same surface format as has been specified when opening the video writer.
771 gpu::VideoWriter_GPU::EncoderParams
772 -----------------------------------
773 .. ocv:struct:: gpu::VideoWriter_GPU::EncoderParams
775 Different parameters for CUDA video encoder. ::
779 int P_Interval; // NVVE_P_INTERVAL,
780 int IDR_Period; // NVVE_IDR_PERIOD,
781 int DynamicGOP; // NVVE_DYNAMIC_GOP,
782 int RCType; // NVVE_RC_TYPE,
783 int AvgBitrate; // NVVE_AVG_BITRATE,
784 int PeakBitrate; // NVVE_PEAK_BITRATE,
785 int QP_Level_Intra; // NVVE_QP_LEVEL_INTRA,
786 int QP_Level_InterP; // NVVE_QP_LEVEL_INTER_P,
787 int QP_Level_InterB; // NVVE_QP_LEVEL_INTER_B,
788 int DeblockMode; // NVVE_DEBLOCK_MODE,
789 int ProfileLevel; // NVVE_PROFILE_LEVEL,
790 int ForceIntra; // NVVE_FORCE_INTRA,
791 int ForceIDR; // NVVE_FORCE_IDR,
792 int ClearStat; // NVVE_CLEAR_STAT,
793 int DIMode; // NVVE_SET_DEINTERLACE,
794 int Presets; // NVVE_PRESETS,
795 int DisableCabac; // NVVE_DISABLE_CABAC,
796 int NaluFramingType; // NVVE_CONFIGURE_NALU_FRAMING_TYPE
797 int DisableSPSPPS; // NVVE_DISABLE_SPS_PPS
800 explicit EncoderParams(const std::string& configFile);
802 void load(const std::string& configFile);
803 void save(const std::string& configFile) const;
808 gpu::VideoWriter_GPU::EncoderParams::EncoderParams
809 --------------------------------------------------
812 .. ocv:function:: gpu::VideoWriter_GPU::EncoderParams::EncoderParams()
813 .. ocv:function:: gpu::VideoWriter_GPU::EncoderParams::EncoderParams(const std::string& configFile)
815 :param configFile: Config file name.
817 Creates default parameters or reads parameters from config file.
821 gpu::VideoWriter_GPU::EncoderParams::load
822 -----------------------------------------
823 Reads parameters from config file.
825 .. ocv:function:: void gpu::VideoWriter_GPU::EncoderParams::load(const std::string& configFile)
827 :param configFile: Config file name.
831 gpu::VideoWriter_GPU::EncoderParams::save
832 -----------------------------------------
833 Saves parameters to config file.
835 .. ocv:function:: void gpu::VideoWriter_GPU::EncoderParams::save(const std::string& configFile) const
837 :param configFile: Config file name.
841 gpu::VideoWriter_GPU::EncoderCallBack
842 -------------------------------------
843 .. ocv:class:: gpu::VideoWriter_GPU::EncoderCallBack
845 Callbacks for CUDA video encoder. ::
847 class EncoderCallBack
857 virtual ~EncoderCallBack() {}
859 virtual unsigned char* acquireBitStream(int* bufferSize) = 0;
860 virtual void releaseBitStream(unsigned char* data, int size) = 0;
861 virtual void onBeginFrame(int frameNumber, PicType picType) = 0;
862 virtual void onEndFrame(int frameNumber, PicType picType) = 0;
867 gpu::VideoWriter_GPU::EncoderCallBack::acquireBitStream
868 -------------------------------------------------------
869 Callback function to signal the start of bitstream that is to be encoded.
871 .. ocv:function:: virtual uchar* gpu::VideoWriter_GPU::EncoderCallBack::acquireBitStream(int* bufferSize) = 0
873 Callback must allocate buffer for CUDA encoder and return pointer to it and it's size.
877 gpu::VideoWriter_GPU::EncoderCallBack::releaseBitStream
878 -------------------------------------------------------
879 Callback function to signal that the encoded bitstream is ready to be written to file.
881 .. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::releaseBitStream(unsigned char* data, int size) = 0
885 gpu::VideoWriter_GPU::EncoderCallBack::onBeginFrame
886 ---------------------------------------------------
887 Callback function to signal that the encoding operation on the frame has started.
889 .. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::onBeginFrame(int frameNumber, PicType picType) = 0
891 :param picType: Specify frame type (I-Frame, P-Frame or B-Frame).
895 gpu::VideoWriter_GPU::EncoderCallBack::onEndFrame
896 -------------------------------------------------
897 Callback function signals that the encoding operation on the frame has finished.
899 .. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::onEndFrame(int frameNumber, PicType picType) = 0
901 :param picType: Specify frame type (I-Frame, P-Frame or B-Frame).
907 Class for reading video from files.
909 .. ocv:class:: gpu::VideoReader_GPU
911 .. note:: Currently only Windows and Linux platforms are supported.
915 gpu::VideoReader_GPU::Codec
916 ---------------------------
918 Video codecs supported by :ocv:class:`gpu::VideoReader_GPU` .
920 .. ocv:enum:: gpu::VideoReader_GPU::Codec
922 .. ocv:emember:: MPEG1 = 0
923 .. ocv:emember:: MPEG2
924 .. ocv:emember:: MPEG4
926 .. ocv:emember:: H264
927 .. ocv:emember:: JPEG
928 .. ocv:emember:: H264_SVC
929 .. ocv:emember:: H264_MVC
931 .. ocv:emember:: Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V'))
935 .. ocv:emember:: Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2'))
939 .. ocv:emember:: Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2'))
943 .. ocv:emember:: Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V'))
947 .. ocv:emember:: Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y'))
952 gpu::VideoReader_GPU::ChromaFormat
953 ----------------------------------
955 Chroma formats supported by :ocv:class:`gpu::VideoReader_GPU` .
957 .. ocv:enum:: gpu::VideoReader_GPU::ChromaFormat
959 .. ocv:emember:: Monochrome = 0
960 .. ocv:emember:: YUV420
961 .. ocv:emember:: YUV422
962 .. ocv:emember:: YUV444
965 gpu::VideoReader_GPU::FormatInfo
966 --------------------------------
967 .. ocv:struct:: gpu::VideoReader_GPU::FormatInfo
969 Struct providing information about video file format. ::
974 ChromaFormat chromaFormat;
980 gpu::VideoReader_GPU::VideoReader_GPU
981 -------------------------------------
984 .. ocv:function:: gpu::VideoReader_GPU::VideoReader_GPU()
985 .. ocv:function:: gpu::VideoReader_GPU::VideoReader_GPU(const std::string& filename)
986 .. ocv:function:: gpu::VideoReader_GPU::VideoReader_GPU(const cv::Ptr<VideoSource>& source)
988 :param filename: Name of the input video file.
990 :param source: Video file parser implemented by user.
992 The constructors initialize video reader. FFMPEG is used to read videos. User can implement own demultiplexing with :ocv:class:`gpu::VideoReader_GPU::VideoSource` .
996 gpu::VideoReader_GPU::open
997 --------------------------
998 Initializes or reinitializes video reader.
1000 .. ocv:function:: void gpu::VideoReader_GPU::open(const std::string& filename)
1001 .. ocv:function:: void gpu::VideoReader_GPU::open(const cv::Ptr<VideoSource>& source)
1003 The method opens video reader. Parameters are the same as in the constructor :ocv:func:`gpu::VideoReader_GPU::VideoReader_GPU` . The method throws :ocv:class:`Exception` if error occurs.
1007 gpu::VideoReader_GPU::isOpened
1008 ------------------------------
1009 Returns true if video reader has been successfully initialized.
1011 .. ocv:function:: bool gpu::VideoReader_GPU::isOpened() const
1015 gpu::VideoReader_GPU::close
1016 ---------------------------
1017 Releases the video reader.
1019 .. ocv:function:: void gpu::VideoReader_GPU::close()
1023 gpu::VideoReader_GPU::read
1024 --------------------------
1025 Grabs, decodes and returns the next video frame.
1027 .. ocv:function:: bool gpu::VideoReader_GPU::read(GpuMat& image)
1029 If no frames has been grabbed (there are no more frames in video file), the methods return ``false`` . The method throws :ocv:class:`Exception` if error occurs.
1033 gpu::VideoReader_GPU::format
1034 ----------------------------
1035 Returns information about video file format.
1037 .. ocv:function:: FormatInfo gpu::VideoReader_GPU::format() const
1039 The method throws :ocv:class:`Exception` if video reader wasn't initialized.
1043 gpu::VideoReader_GPU::dumpFormat
1044 --------------------------------
1045 Dump information about video file format to specified stream.
1047 .. ocv:function:: void gpu::VideoReader_GPU::dumpFormat(std::ostream& st)
1049 :param st: Output stream.
1051 The method throws :ocv:class:`Exception` if video reader wasn't initialized.
1055 gpu::VideoReader_GPU::VideoSource
1056 -----------------------------------
1057 .. ocv:class:: gpu::VideoReader_GPU::VideoSource
1059 Interface for video demultiplexing. ::
1065 virtual ~VideoSource() {}
1067 virtual FormatInfo format() const = 0;
1068 virtual void start() = 0;
1069 virtual void stop() = 0;
1070 virtual bool isStarted() const = 0;
1071 virtual bool hasError() const = 0;
1074 bool parseVideoData(const unsigned char* data, size_t size, bool endOfStream = false);
1077 User can implement own demultiplexing by implementing this interface.
1081 gpu::VideoReader_GPU::VideoSource::format
1082 -----------------------------------------
1083 Returns information about video file format.
1085 .. ocv:function:: virtual FormatInfo gpu::VideoReader_GPU::VideoSource::format() const = 0
1089 gpu::VideoReader_GPU::VideoSource::start
1090 ----------------------------------------
1093 .. ocv:function:: virtual void gpu::VideoReader_GPU::VideoSource::start() = 0
1095 Implementation must create own thread with video processing and call periodic :ocv:func:`gpu::VideoReader_GPU::VideoSource::parseVideoData` .
1099 gpu::VideoReader_GPU::VideoSource::stop
1100 ---------------------------------------
1103 .. ocv:function:: virtual void gpu::VideoReader_GPU::VideoSource::stop() = 0
1107 gpu::VideoReader_GPU::VideoSource::isStarted
1108 --------------------------------------------
1109 Returns ``true`` if processing was successfully started.
1111 .. ocv:function:: virtual bool gpu::VideoReader_GPU::VideoSource::isStarted() const = 0
1115 gpu::VideoReader_GPU::VideoSource::hasError
1116 -------------------------------------------
1117 Returns ``true`` if error occured during processing.
1119 .. ocv:function:: virtual bool gpu::VideoReader_GPU::VideoSource::hasError() const = 0
1123 gpu::VideoReader_GPU::VideoSource::parseVideoData
1124 -------------------------------------------------
1125 Parse next video frame. Implementation must call this method after new frame was grabbed.
1127 .. ocv:function:: bool gpu::VideoReader_GPU::VideoSource::parseVideoData(const uchar* data, size_t size, bool endOfStream = false)
1129 :param data: Pointer to frame data. Can be ``NULL`` if ``endOfStream`` if ``true`` .
1131 :param size: Size in bytes of current frame.
1133 :param endOfStream: Indicates that it is end of stream.
1137 .. [Brox2004] T. Brox, A. Bruhn, N. Papenberg, J. Weickert. *High accuracy optical flow estimation based on a theory for warping*. ECCV 2004.
1138 .. [FGD2003] Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian. *Foreground Object Detection from Videos Containing Complex Background*. ACM MM2003 9p, 2003.
1139 .. [MOG2001] P. KadewTraKuPong and R. Bowden. *An improved adaptive background mixture model for real-time tracking with shadow detection*. Proc. 2nd European Workshop on Advanced Video-Based Surveillance Systems, 2001
1140 .. [MOG2004] Z. Zivkovic. *Improved adaptive Gausian mixture model for background subtraction*. International Conference Pattern Recognition, UK, August, 2004
1141 .. [ShadowDetect2003] Prati, Mikic, Trivedi and Cucchiarra. *Detecting Moving Shadows...*. IEEE PAMI, 2003
1142 .. [GMG2012] A. Godbehere, A. Matsukawa and K. Goldberg. *Visual Tracking of Human Visitors under Variable-Lighting Conditions for a Responsive Audio Art Installation*. American Control Conference, Montreal, June 2012