CLAHE Python bindings
[profile/ivi/opencv.git] / modules / gpu / doc / video.rst
1 Video Analysis
2 ==============
3
4 .. highlight:: cpp
5
6
7
8 gpu::BroxOpticalFlow
9 --------------------
10 .. ocv:class:: gpu::BroxOpticalFlow
11
12 Class computing the optical flow for two images using Brox et al Optical Flow algorithm ([Brox2004]_). ::
13
14     class BroxOpticalFlow
15     {
16     public:
17         BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_);
18
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());
25
26         //! flow smoothness
27         float alpha;
28
29         //! gradient constancy importance
30         float gamma;
31
32         //! pyramid scale factor
33         float scale_factor;
34
35         //! number of lagged non-linearity iterations (inner loop)
36         int inner_iterations;
37
38         //! number of warping iterations (number of pyramid levels)
39         int outer_iterations;
40
41         //! number of linear system solver iterations
42         int solver_iterations;
43
44         GpuMat buf;
45     };
46
47
48
49 gpu::GoodFeaturesToTrackDetector_GPU
50 ------------------------------------
51 .. ocv:class:: gpu::GoodFeaturesToTrackDetector_GPU
52
53 Class used for strong corners detection on an image. ::
54
55     class GoodFeaturesToTrackDetector_GPU
56     {
57     public:
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);
60
61         void operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat());
62
63         int maxCorners;
64         double qualityLevel;
65         double minDistance;
66
67         int blockSize;
68         bool useHarrisDetector;
69         double harrisK;
70
71         void releaseMemory();
72     };
73
74 The class finds the most prominent corners in the image.
75
76 .. seealso:: :ocv:func:`goodFeaturesToTrack`
77
78
79
80 gpu::GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU
81 ---------------------------------------------------------------------
82 Constructor.
83
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)
85
86     :param maxCorners: Maximum number of corners to return. If there are more corners than are found, the strongest of them is returned.
87
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.
89
90     :param minDistance: Minimum possible Euclidean distance between the returned corners.
91
92     :param blockSize: Size of an average block for computing a derivative covariation matrix over each pixel neighborhood. See  :ocv:func:`cornerEigenValsAndVecs` .
93
94     :param useHarrisDetector: Parameter indicating whether to use a Harris detector (see :ocv:func:`gpu::cornerHarris`) or :ocv:func:`gpu::cornerMinEigenVal`.
95
96     :param harrisK: Free parameter of the Harris detector.
97
98
99
100 gpu::GoodFeaturesToTrackDetector_GPU::operator ()
101 -------------------------------------------------
102 Finds the most prominent corners in the image.
103
104 .. ocv:function:: void gpu::GoodFeaturesToTrackDetector_GPU::operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat())
105
106     :param image: Input 8-bit, single-channel image.
107
108     :param corners: Output vector of detected corners (it will be one row matrix with CV_32FC2 type).
109
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.
111
112 .. seealso:: :ocv:func:`goodFeaturesToTrack`
113
114
115
116 gpu::GoodFeaturesToTrackDetector_GPU::releaseMemory
117 ---------------------------------------------------
118 Releases inner buffers memory.
119
120 .. ocv:function:: void gpu::GoodFeaturesToTrackDetector_GPU::releaseMemory()
121
122
123
124 gpu::FarnebackOpticalFlow
125 -------------------------
126 .. ocv:class:: gpu::FarnebackOpticalFlow
127
128 Class computing a dense optical flow using the Gunnar Farneback’s algorithm. ::
129
130     class CV_EXPORTS FarnebackOpticalFlow
131     {
132     public:
133         FarnebackOpticalFlow()
134         {
135             numLevels = 5;
136             pyrScale = 0.5;
137             fastPyramids = false;
138             winSize = 13;
139             numIters = 10;
140             polyN = 5;
141             polySigma = 1.1;
142             flags = 0;
143         }
144
145         int numLevels;
146         double pyrScale;
147         bool fastPyramids;
148         int winSize;
149         int numIters;
150         int polyN;
151         double polySigma;
152         int flags;
153
154         void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null());
155
156         void releaseMemory();
157
158     private:
159         /* hidden */
160     };
161
162
163
164 gpu::FarnebackOpticalFlow::operator ()
165 --------------------------------------
166 Computes a dense optical flow using the Gunnar Farneback’s algorithm.
167
168 .. ocv:function:: void gpu::FarnebackOpticalFlow::operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null())
169
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
174     :param s: Stream
175
176 .. seealso:: :ocv:func:`calcOpticalFlowFarneback`
177
178
179
180 gpu::FarnebackOpticalFlow::releaseMemory
181 ----------------------------------------
182 Releases unused auxiliary memory buffers.
183
184 .. ocv:function:: void gpu::FarnebackOpticalFlow::releaseMemory()
185
186
187
188 gpu::PyrLKOpticalFlow
189 ---------------------
190 .. ocv:class:: gpu::PyrLKOpticalFlow
191
192 Class used for calculating an optical flow. ::
193
194     class PyrLKOpticalFlow
195     {
196     public:
197         PyrLKOpticalFlow();
198
199         void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts,
200             GpuMat& status, GpuMat* err = 0);
201
202         void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0);
203
204         Size winSize;
205         int maxLevel;
206         int iters;
207         bool useInitialFlow;
208
209         void releaseMemory();
210     };
211
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.
213
214 .. seealso:: :ocv:func:`calcOpticalFlowPyrLK`
215
216
217
218 gpu::PyrLKOpticalFlow::sparse
219 -----------------------------
220 Calculate an optical flow for a sparse feature set.
221
222 .. ocv:function:: void gpu::PyrLKOpticalFlow::sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts, GpuMat& status, GpuMat* err = 0)
223
224     :param prevImg: First 8-bit input image (supports both grayscale and color images).
225
226     :param nextImg: Second input image of the same size and the same type as  ``prevImg`` .
227
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.
229
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.
231
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.
233
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.
235
236 .. seealso:: :ocv:func:`calcOpticalFlowPyrLK`
237
238
239
240 gpu::PyrLKOpticalFlow::dense
241 -----------------------------
242 Calculate dense optical flow.
243
244 .. ocv:function:: void gpu::PyrLKOpticalFlow::dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0)
245
246     :param prevImg: First 8-bit grayscale input image.
247
248     :param nextImg: Second input image of the same size and the same type as  ``prevImg`` .
249
250     :param u: Horizontal component of the optical flow of the same size as input images, 32-bit floating-point, single-channel
251
252     :param v: Vertical component of the optical flow of the same size as input images, 32-bit floating-point, single-channel
253
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.
255
256
257
258 gpu::PyrLKOpticalFlow::releaseMemory
259 ------------------------------------
260 Releases inner buffers memory.
261
262 .. ocv:function:: void gpu::PyrLKOpticalFlow::releaseMemory()
263
264
265
266 gpu::interpolateFrames
267 ----------------------
268 Interpolates frames (images) using provided optical flow (displacement field).
269
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())
271
272     :param frame0: First frame (32-bit floating point images, single channel).
273
274     :param frame1: Second frame. Must have the same type and size as ``frame0`` .
275
276     :param fu: Forward horizontal displacement.
277
278     :param fv: Forward vertical displacement.
279
280     :param bu: Backward horizontal displacement.
281
282     :param bv: Backward vertical displacement.
283
284     :param pos: New frame position.
285
286     :param newFrame: Output image.
287
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.
289
290     :param stream: Stream for the asynchronous version.
291
292
293
294 gpu::FGDStatModel
295 -----------------
296 .. ocv:class:: gpu::FGDStatModel
297
298 Class used for background/foreground segmentation. ::
299
300     class FGDStatModel
301     {
302     public:
303         struct Params
304         {
305             ...
306         };
307
308         explicit FGDStatModel(int out_cn = 3);
309         explicit FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3);
310
311         ~FGDStatModel();
312
313         void create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params());
314         void release();
315
316         int update(const cv::gpu::GpuMat& curFrame);
317
318         //8UC3 or 8UC4 reference background image
319         cv::gpu::GpuMat background;
320
321         //8UC1 foreground image
322         cv::gpu::GpuMat foreground;
323
324         std::vector< std::vector<cv::Point> > foreground_regions;
325     };
326
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]_.
328
329   The results are available through the class fields:
330
331     .. ocv:member:: cv::gpu::GpuMat background
332
333         The output background image.
334
335     .. ocv:member:: cv::gpu::GpuMat foreground
336
337         The output foreground mask as an 8-bit binary image.
338
339     .. ocv:member:: cv::gpu::GpuMat foreground_regions
340
341         The output foreground regions calculated by :ocv:func:`findContours`.
342
343
344
345 gpu::FGDStatModel::FGDStatModel
346 -------------------------------
347 Constructors.
348
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)
351
352     :param firstFrame: First frame from video stream. Supports 3- and 4-channels input ( ``CV_8UC3`` and ``CV_8UC4`` ).
353
354     :param params: Algorithm's parameters. See [FGD2003]_ for explanation.
355
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.
357
358 .. seealso:: :ocv:func:`gpu::FGDStatModel::create`
359
360
361
362 gpu::FGDStatModel::create
363 -------------------------
364 Initializes background model.
365
366 .. ocv:function:: void gpu::FGDStatModel::create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params())
367
368     :param firstFrame: First frame from video stream. Supports 3- and 4-channels input ( ``CV_8UC3`` and ``CV_8UC4`` ).
369
370     :param params: Algorithm's parameters. See [FGD2003]_ for explanation.
371
372
373
374 gpu::FGDStatModel::release
375 --------------------------
376 Releases all inner buffer's memory.
377
378 .. ocv:function:: void gpu::FGDStatModel::release()
379
380
381
382 gpu::FGDStatModel::update
383 --------------------------
384 Updates the background model and returns foreground regions count.
385
386 .. ocv:function:: int gpu::FGDStatModel::update(const cv::gpu::GpuMat& curFrame)
387
388     :param curFrame: Next video frame.
389
390
391
392 gpu::MOG_GPU
393 ------------
394 .. ocv:class:: gpu::MOG_GPU
395
396 Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm. ::
397
398     class MOG_GPU
399     {
400     public:
401         MOG_GPU(int nmixtures = -1);
402
403         void initialize(Size frameSize, int frameType);
404
405         void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null());
406
407         void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
408
409         void release();
410
411         int history;
412         float varThreshold;
413         float backgroundRatio;
414         float noiseSigma;
415     };
416
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]_.
418
419 .. seealso:: :ocv:class:`BackgroundSubtractorMOG`
420
421
422
423 gpu::MOG_GPU::MOG_GPU
424 ---------------------
425 The constructor.
426
427 .. ocv:function:: gpu::MOG_GPU::MOG_GPU(int nmixtures = -1)
428
429     :param nmixtures: Number of Gaussian mixtures.
430
431 Default constructor sets all parameters to default values.
432
433
434
435 gpu::MOG_GPU::operator()
436 ------------------------
437 Updates the background model and returns the foreground mask.
438
439 .. ocv:function:: void gpu::MOG_GPU::operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null())
440
441     :param frame: Next video frame.
442
443     :param fgmask: The output foreground mask as an 8-bit binary image.
444
445     :param stream: Stream for the asynchronous version.
446
447
448
449 gpu::MOG_GPU::getBackgroundImage
450 --------------------------------
451 Computes a background image.
452
453 .. ocv:function:: void gpu::MOG_GPU::getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const
454
455     :param backgroundImage: The output background image.
456
457     :param stream: Stream for the asynchronous version.
458
459
460
461 gpu::MOG_GPU::release
462 ---------------------
463 Releases all inner buffer's memory.
464
465 .. ocv:function:: void gpu::MOG_GPU::release()
466
467
468
469 gpu::MOG2_GPU
470 -------------
471 .. ocv:class:: gpu::MOG2_GPU
472
473 Gaussian Mixture-based Background/Foreground Segmentation Algorithm. ::
474
475     class MOG2_GPU
476     {
477     public:
478         MOG2_GPU(int nmixtures = -1);
479
480         void initialize(Size frameSize, int frameType);
481
482         void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null());
483
484         void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
485
486         void release();
487
488         // parameters
489         ...
490     };
491
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]_.
493
494   Here are important members of the class that control the algorithm, which you can set after constructing the class instance:
495
496     .. ocv:member:: float backgroundRatio
497
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.
499
500     .. ocv:member:: float varThreshold
501
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.
503
504     .. ocv:member:: float fVarInit
505
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.
507
508     .. ocv:member:: float fVarMin
509
510         Parameter used to further control the variance.
511
512     .. ocv:member:: float fVarMax
513
514         Parameter used to further control the variance.
515
516     .. ocv:member:: float fCT
517
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.
519
520     .. ocv:member:: uchar nShadowDetection
521
522         The value for marking shadow pixels in the output foreground mask. Default value is 127.
523
524     .. ocv:member:: float fTau
525
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]_.
527
528     .. ocv:member:: bool bShadowDetection
529
530         Parameter defining whether shadow detection should be enabled.
531
532 .. seealso:: :ocv:class:`BackgroundSubtractorMOG2`
533
534
535
536 gpu::MOG2_GPU::MOG2_GPU
537 -----------------------
538 The constructor.
539
540 .. ocv:function:: gpu::MOG2_GPU::MOG2_GPU(int nmixtures = -1)
541
542     :param nmixtures: Number of Gaussian mixtures.
543
544 Default constructor sets all parameters to default values.
545
546
547
548 gpu::MOG2_GPU::operator()
549 -------------------------
550 Updates the background model and returns the foreground mask.
551
552 .. ocv:function:: void gpu::MOG2_GPU::operator()( const GpuMat& frame, GpuMat& fgmask, float learningRate=-1.0f, Stream& stream=Stream::Null() )
553
554     :param frame: Next video frame.
555
556     :param fgmask: The output foreground mask as an 8-bit binary image.
557
558     :param stream: Stream for the asynchronous version.
559
560
561
562 gpu::MOG2_GPU::getBackgroundImage
563 ---------------------------------
564 Computes a background image.
565
566 .. ocv:function:: void gpu::MOG2_GPU::getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const
567
568     :param backgroundImage: The output background image.
569
570     :param stream: Stream for the asynchronous version.
571
572
573
574 gpu::MOG2_GPU::release
575 ----------------------
576 Releases all inner buffer's memory.
577
578 .. ocv:function:: void gpu::MOG2_GPU::release()
579
580
581
582 gpu::GMG_GPU
583 ------------
584 .. ocv:class:: gpu::GMG_GPU
585
586   Class used for background/foreground segmentation. ::
587
588     class GMG_GPU_GPU
589     {
590     public:
591         GMG_GPU();
592
593         void initialize(Size frameSize, float min = 0.0f, float max = 255.0f);
594
595         void operator ()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null());
596
597         void release();
598
599         int    maxFeatures;
600         float  learningRate;
601         int    numInitializationFrames;
602         int    quantizationLevels;
603         float  backgroundPrior;
604         float  decisionThreshold;
605         int    smoothingRadius;
606
607         ...
608     };
609
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]_.
611
612   Here are important members of the class that control the algorithm, which you can set after constructing the class instance:
613
614     .. ocv:member:: int maxFeatures
615
616         Total number of distinct colors to maintain in histogram.
617
618     .. ocv:member:: float learningRate
619
620         Set between 0.0 and 1.0, determines how quickly features are "forgotten" from histograms.
621
622     .. ocv:member:: int numInitializationFrames
623
624         Number of frames of video to use to initialize histograms.
625
626     .. ocv:member:: int quantizationLevels
627
628         Number of discrete levels in each channel to be used in histograms.
629
630     .. ocv:member:: float backgroundPrior
631
632         Prior probability that any given pixel is a background pixel. A sensitivity parameter.
633
634     .. ocv:member:: float decisionThreshold
635
636         Value above which pixel is determined to be FG.
637
638     .. ocv:member:: float smoothingRadius
639
640         Smoothing radius, in pixels, for cleaning up FG image.
641
642
643
644 gpu::GMG_GPU::GMG_GPU
645 ---------------------
646 The default constructor.
647
648 .. ocv:function:: gpu::GMG_GPU::GMG_GPU()
649
650 Default constructor sets all parameters to default values.
651
652
653
654 gpu::GMG_GPU::initialize
655 ------------------------
656 Initialize background model and allocates all inner buffers.
657
658 .. ocv:function:: void gpu::GMG_GPU::initialize(Size frameSize, float min = 0.0f, float max = 255.0f)
659
660     :param frameSize: Input frame size.
661
662     :param min: Minimum value taken on by pixels in image sequence. Usually 0.
663
664     :param max: Maximum value taken on by pixels in image sequence, e.g. 1.0 or 255.
665
666
667
668 gpu::GMG_GPU::operator()
669 ------------------------
670 Updates the background model and returns the foreground mask
671
672 .. ocv:function:: void gpu::GMG_GPU::operator ()( const GpuMat& frame, GpuMat& fgmask, float learningRate=-1.0f, Stream& stream=Stream::Null() )
673
674     :param frame: Next video frame.
675
676     :param fgmask: The output foreground mask as an 8-bit binary image.
677
678     :param stream: Stream for the asynchronous version.
679
680
681
682 gpu::GMG_GPU::release
683 ---------------------
684 Releases all inner buffer's memory.
685
686 .. ocv:function:: void gpu::GMG_GPU::release()
687
688
689
690 gpu::VideoWriter_GPU
691 ---------------------
692 Video writer class.
693
694 .. ocv:class:: gpu::VideoWriter_GPU
695
696 The class uses H264 video codec.
697
698 .. note:: Currently only Windows platform is supported.
699
700
701
702 gpu::VideoWriter_GPU::VideoWriter_GPU
703 -------------------------------------
704 Constructors.
705
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)
711
712     :param fileName: Name of the output video file. Only AVI file format is supported.
713
714     :param frameSize: Size of the input video frames.
715
716     :param fps: Framerate of the created video stream.
717
718     :param params: Encoder parameters. See :ocv:struct:`gpu::VideoWriter_GPU::EncoderParams` .
719
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.
721
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.
723
724 The constructors initialize video writer. FFMPEG is used to write videos. User can implement own multiplexing with :ocv:class:`gpu::VideoWriter_GPU::EncoderCallBack` .
725
726
727
728 gpu::VideoWriter_GPU::open
729 --------------------------
730 Initializes or reinitializes video writer.
731
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)
736
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.
738
739
740
741 gpu::VideoWriter_GPU::isOpened
742 ------------------------------
743 Returns true if video writer has been successfully initialized.
744
745 .. ocv:function:: bool gpu::VideoWriter_GPU::isOpened() const
746
747
748
749 gpu::VideoWriter_GPU::close
750 ---------------------------
751 Releases the video writer.
752
753 .. ocv:function:: void gpu::VideoWriter_GPU::close()
754
755
756
757 gpu::VideoWriter_GPU::write
758 ---------------------------
759 Writes the next video frame.
760
761 .. ocv:function:: void gpu::VideoWriter_GPU::write(const cv::gpu::GpuMat& image, bool lastFrame = false)
762
763     :param image: The written frame.
764
765     :param lastFrame: Indicates that it is end of stream. The parameter can be ignored.
766
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.
768
769
770
771 gpu::VideoWriter_GPU::EncoderParams
772 -----------------------------------
773 .. ocv:struct:: gpu::VideoWriter_GPU::EncoderParams
774
775 Different parameters for CUDA video encoder. ::
776
777     struct EncoderParams
778     {
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
798
799         EncoderParams();
800         explicit EncoderParams(const std::string& configFile);
801
802         void load(const std::string& configFile);
803         void save(const std::string& configFile) const;
804     };
805
806
807
808 gpu::VideoWriter_GPU::EncoderParams::EncoderParams
809 --------------------------------------------------
810 Constructors.
811
812 .. ocv:function:: gpu::VideoWriter_GPU::EncoderParams::EncoderParams()
813 .. ocv:function:: gpu::VideoWriter_GPU::EncoderParams::EncoderParams(const std::string& configFile)
814
815     :param configFile: Config file name.
816
817 Creates default parameters or reads parameters from config file.
818
819
820
821 gpu::VideoWriter_GPU::EncoderParams::load
822 -----------------------------------------
823 Reads parameters from config file.
824
825 .. ocv:function:: void gpu::VideoWriter_GPU::EncoderParams::load(const std::string& configFile)
826
827     :param configFile: Config file name.
828
829
830
831 gpu::VideoWriter_GPU::EncoderParams::save
832 -----------------------------------------
833 Saves parameters to config file.
834
835 .. ocv:function:: void gpu::VideoWriter_GPU::EncoderParams::save(const std::string& configFile) const
836
837     :param configFile: Config file name.
838
839
840
841 gpu::VideoWriter_GPU::EncoderCallBack
842 -------------------------------------
843 .. ocv:class:: gpu::VideoWriter_GPU::EncoderCallBack
844
845 Callbacks for CUDA video encoder. ::
846
847     class EncoderCallBack
848     {
849     public:
850         enum PicType
851         {
852             IFRAME = 1,
853             PFRAME = 2,
854             BFRAME = 3
855         };
856
857         virtual ~EncoderCallBack() {}
858
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;
863     };
864
865
866
867 gpu::VideoWriter_GPU::EncoderCallBack::acquireBitStream
868 -------------------------------------------------------
869 Callback function to signal the start of bitstream that is to be encoded.
870
871 .. ocv:function:: virtual uchar* gpu::VideoWriter_GPU::EncoderCallBack::acquireBitStream(int* bufferSize) = 0
872
873 Callback must allocate buffer for CUDA encoder and return pointer to it and it's size.
874
875
876
877 gpu::VideoWriter_GPU::EncoderCallBack::releaseBitStream
878 -------------------------------------------------------
879 Callback function to signal that the encoded bitstream is ready to be written to file.
880
881 .. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::releaseBitStream(unsigned char* data, int size) = 0
882
883
884
885 gpu::VideoWriter_GPU::EncoderCallBack::onBeginFrame
886 ---------------------------------------------------
887 Callback function to signal that the encoding operation on the frame has started.
888
889 .. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::onBeginFrame(int frameNumber, PicType picType) = 0
890
891     :param picType: Specify frame type (I-Frame, P-Frame or B-Frame).
892
893
894
895 gpu::VideoWriter_GPU::EncoderCallBack::onEndFrame
896 -------------------------------------------------
897 Callback function signals that the encoding operation on the frame has finished.
898
899 .. ocv:function:: virtual void gpu::VideoWriter_GPU::EncoderCallBack::onEndFrame(int frameNumber, PicType picType) = 0
900
901     :param picType: Specify frame type (I-Frame, P-Frame or B-Frame).
902
903
904
905 gpu::VideoReader_GPU
906 --------------------
907 Class for reading video from files.
908
909 .. ocv:class:: gpu::VideoReader_GPU
910
911 .. note:: Currently only Windows and Linux platforms are supported.
912
913
914
915 gpu::VideoReader_GPU::Codec
916 ---------------------------
917
918 Video codecs supported by :ocv:class:`gpu::VideoReader_GPU` .
919
920 .. ocv:enum:: gpu::VideoReader_GPU::Codec
921
922   .. ocv:emember:: MPEG1 = 0
923   .. ocv:emember:: MPEG2
924   .. ocv:emember:: MPEG4
925   .. ocv:emember:: VC1
926   .. ocv:emember:: H264
927   .. ocv:emember:: JPEG
928   .. ocv:emember:: H264_SVC
929   .. ocv:emember:: H264_MVC
930
931   .. ocv:emember:: Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V'))
932
933         Y,U,V (4:2:0)
934
935   .. ocv:emember:: Uncompressed_YV12   = (('Y'<<24)|('V'<<16)|('1'<<8)|('2'))
936
937         Y,V,U (4:2:0)
938
939   .. ocv:emember:: Uncompressed_NV12   = (('N'<<24)|('V'<<16)|('1'<<8)|('2'))
940
941         Y,UV  (4:2:0)
942
943   .. ocv:emember:: Uncompressed_YUYV   = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V'))
944
945         YUYV/YUY2 (4:2:2)
946
947   .. ocv:emember:: Uncompressed_UYVY   = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y'))
948
949         UYVY (4:2:2)
950
951
952 gpu::VideoReader_GPU::ChromaFormat
953 ----------------------------------
954
955 Chroma formats supported by :ocv:class:`gpu::VideoReader_GPU` .
956
957 .. ocv:enum:: gpu::VideoReader_GPU::ChromaFormat
958
959   .. ocv:emember:: Monochrome = 0
960   .. ocv:emember:: YUV420
961   .. ocv:emember:: YUV422
962   .. ocv:emember:: YUV444
963
964
965 gpu::VideoReader_GPU::FormatInfo
966 --------------------------------
967 .. ocv:struct:: gpu::VideoReader_GPU::FormatInfo
968
969 Struct providing information about video file format. ::
970
971     struct FormatInfo
972     {
973         Codec codec;
974         ChromaFormat chromaFormat;
975         int width;
976         int height;
977     };
978
979
980 gpu::VideoReader_GPU::VideoReader_GPU
981 -------------------------------------
982 Constructors.
983
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)
987
988     :param filename: Name of the input video file.
989
990     :param source: Video file parser implemented by user.
991
992 The constructors initialize video reader. FFMPEG is used to read videos. User can implement own demultiplexing with :ocv:class:`gpu::VideoReader_GPU::VideoSource` .
993
994
995
996 gpu::VideoReader_GPU::open
997 --------------------------
998 Initializes or reinitializes video reader.
999
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)
1002
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.
1004
1005
1006
1007 gpu::VideoReader_GPU::isOpened
1008 ------------------------------
1009 Returns true if video reader has been successfully initialized.
1010
1011 .. ocv:function:: bool gpu::VideoReader_GPU::isOpened() const
1012
1013
1014
1015 gpu::VideoReader_GPU::close
1016 ---------------------------
1017 Releases the video reader.
1018
1019 .. ocv:function:: void gpu::VideoReader_GPU::close()
1020
1021
1022
1023 gpu::VideoReader_GPU::read
1024 --------------------------
1025 Grabs, decodes and returns the next video frame.
1026
1027 .. ocv:function:: bool gpu::VideoReader_GPU::read(GpuMat& image)
1028
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.
1030
1031
1032
1033 gpu::VideoReader_GPU::format
1034 ----------------------------
1035 Returns information about video file format.
1036
1037 .. ocv:function:: FormatInfo gpu::VideoReader_GPU::format() const
1038
1039 The method throws :ocv:class:`Exception` if video reader wasn't initialized.
1040
1041
1042
1043 gpu::VideoReader_GPU::dumpFormat
1044 --------------------------------
1045 Dump information about video file format to specified stream.
1046
1047 .. ocv:function:: void gpu::VideoReader_GPU::dumpFormat(std::ostream& st)
1048
1049     :param st: Output stream.
1050
1051 The method throws :ocv:class:`Exception` if video reader wasn't initialized.
1052
1053
1054
1055 gpu::VideoReader_GPU::VideoSource
1056 -----------------------------------
1057 .. ocv:class:: gpu::VideoReader_GPU::VideoSource
1058
1059 Interface for video demultiplexing. ::
1060
1061     class VideoSource
1062     {
1063     public:
1064         VideoSource();
1065         virtual ~VideoSource() {}
1066
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;
1072
1073     protected:
1074         bool parseVideoData(const unsigned char* data, size_t size, bool endOfStream = false);
1075     };
1076
1077 User can implement own demultiplexing by implementing this interface.
1078
1079
1080
1081 gpu::VideoReader_GPU::VideoSource::format
1082 -----------------------------------------
1083 Returns information about video file format.
1084
1085 .. ocv:function:: virtual FormatInfo gpu::VideoReader_GPU::VideoSource::format() const = 0
1086
1087
1088
1089 gpu::VideoReader_GPU::VideoSource::start
1090 ----------------------------------------
1091 Starts processing.
1092
1093 .. ocv:function:: virtual void gpu::VideoReader_GPU::VideoSource::start() = 0
1094
1095 Implementation must create own thread with video processing and call periodic :ocv:func:`gpu::VideoReader_GPU::VideoSource::parseVideoData` .
1096
1097
1098
1099 gpu::VideoReader_GPU::VideoSource::stop
1100 ---------------------------------------
1101 Stops processing.
1102
1103 .. ocv:function:: virtual void gpu::VideoReader_GPU::VideoSource::stop() = 0
1104
1105
1106
1107 gpu::VideoReader_GPU::VideoSource::isStarted
1108 --------------------------------------------
1109 Returns ``true`` if processing was successfully started.
1110
1111 .. ocv:function:: virtual bool gpu::VideoReader_GPU::VideoSource::isStarted() const = 0
1112
1113
1114
1115 gpu::VideoReader_GPU::VideoSource::hasError
1116 -------------------------------------------
1117 Returns ``true`` if error occured during processing.
1118
1119 .. ocv:function:: virtual bool gpu::VideoReader_GPU::VideoSource::hasError() const = 0
1120
1121
1122
1123 gpu::VideoReader_GPU::VideoSource::parseVideoData
1124 -------------------------------------------------
1125 Parse next video frame. Implementation must call this method after new frame was grabbed.
1126
1127 .. ocv:function:: bool gpu::VideoReader_GPU::VideoSource::parseVideoData(const uchar* data, size_t size, bool endOfStream = false)
1128
1129     :param data: Pointer to frame data. Can be ``NULL`` if ``endOfStream`` if ``true`` .
1130
1131     :param size: Size in bytes of current frame.
1132
1133     :param endOfStream: Indicates that it is end of stream.
1134
1135
1136
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