Update to 2.0.0 tree from current Fremantle build
[opencv] / doc / CvAux.tex
1 \chapter{CvAux}
2
3 \section{Stereo Correspondence Functions}
4
5 \cvfunc{FindStereoCorrespondence} 
6
7 Calculates disparity for a stereo-pair.
8
9 \cvexp{
10 cvFindStereoCorrespondence(
11                    \par const  CvArr* leftImage, \par const  CvArr* rightImage,
12                    \par int     mode, \par CvArr*  depthImage,
13                    \par int     maxDisparity,
14                    \par double  param1, \par double  param2, \par double  param3,
15                    \par double  param4, \par double  param5  );
16
17 }{CPP}{PYTHON}
18
19 \begin{description}
20 \cvarg{leftImage}{Left image of the stereo pair, a rectified, grayscale, 8-bit image.}
21 \cvarg{rightImage}{Right image of the stereo pair, a rectified, grayscale, 8-bit image.}
22 \cvarg{mode}{Algorithm used to find a disparity (now only CV\_DISPARITY\_BIRCHFIELD is supported).}
23 \cvarg{depthImage}{Destination depth image, a grayscale, 8-bit image that codes the scaled disparity, so that the zero disparity (corresponding to the points that are very far from the cameras) maps to 0, and the maximum disparity maps to 255.}
24 \cvarg{maxDisparity}{Maximum possible disparity. The closer the objects to the camera, the larger ths value should be. Very large values slow down the process significantly.}
25 \cvarg{param1, param2, param3, param4, param5}{The parameters of the algorithm. param1 is the constant occlusion penalty, param2 is the constant match reward, param3 defines a highly reliable region (set of contiguous pixels whose reliability is at least param3), param4 defines a moderately reliable region, and param5 defines a slightly reliable region. If some parameter is omitted default, its value is used. In Birchfield's algorithm param1 = 25, param2 = 5, param3 = 12, param4 = 15, and param5 = 25 (These values have been taken from "Depth Discontinuities by Pixel-to-Pixel Stereo" Stanford University Technical Report STAN-CS-TR-96-1573, July 1996.).}
26 \end{description}
27
28 The function \texttt{cvFindStereoCorrespondence} calculates a disparity map for two rectified grayscale images.
29
30 Example: Calculating disparity for a pair of 8-bit color images
31
32 \begin{lstlisting}
33 /*--------------------------------------------------------------------------*/
34 IplImage* srcLeft = cvLoadImage("left.jpg",1);
35 IplImage* srcRight = cvLoadImage("right.jpg",1);
36 IplImage* leftImage = cvCreateImage(cvGetSize(srcLeft), IPL\_DEPTH\_8U, 1);
37 IplImage* rightImage = cvCreateImage(cvGetSize(srcRight), IPL\_DEPTH\_8U, 1);
38 IplImage* depthImage = cvCreateImage(cvGetSize(srcRight), IPL\_DEPTH\_8U, 1);
39
40 cvCvtColor(srcLeft, leftImage, CV\_BGR2GRAY);
41 cvCvtColor(srcRight, rightImage, CV\_BGR2GRAY);
42
43 cvFindStereoCorrespondence( leftImage, rightImage, CV\_DISPARITY\_BIRCHFIELD, 
44                             depthImage, 50, 15, 3, 6, 8, 15 );
45 /*--------------------------------------------------------------------------*/
46
47 \end{lstlisting}
48
49 And here is the example stereo pair that can be used to test the example
50
51 \includegraphics{pics/left.jpg}
52
53 \includegraphics{pics/right.jpg}
54
55 \section{View Morphing Functions}
56
57 \cvfunc{MakeScanlines}
58
59 Calculates the coordinates of scanlines for two cameras using a fundamental matrix.
60
61 \cvexp{
62 void cvMakeScanlines( \par const CvMatrix3* matrix, \par CvSize img\_size, \par int* scanlines1,
63                       \par int* scanlines2, \par int* lengths1, \par int* lengths2, \par int* line\_count );
64
65 }{CPP}{PYTHON}
66
67 \begin{description}
68 \cvarg{matrix}{Fundamental matrix.}
69 \cvarg{imgSize}{Size of the image.}
70 \cvarg{scanlines1}{Pointer to the array of calculated scanlines of the first image.}
71 \cvarg{scanlines2}{Pointer to the array of calculated scanlines of the second image.}
72 \cvarg{lengths1}{Pointer to the array of calculated lengths (in pixels) of the first image scanlines.}
73 \cvarg{lengths2}{Pointer to the array of calculated lengths (in pixels) of the second image scanlines.}
74 \cvarg{line\_count}{Pointer to the variable that stores the number of scanlines.}
75 \end{description}
76
77 The function \texttt{cvMakeScanlines} finds the coordinates of scanlines for two images.
78
79 This function returns the number of scanlines. The function does nothing except calculating the number of scanlines if the pointers \texttt{scanlines1} or \texttt{scanlines2} are equal to zero.
80
81 \cvfunc{PreWarpImage}
82
83 Rectifies an image.
84
85 \cvexp{
86 void cvPreWarpImage( \par int line\_count, \par IplImage* img, \par uchar* dst,
87                      \par int* dst\_nums, \par int* scanlines );
88
89 }{CPP}{PYTHON}
90
91 \begin{description}
92 \cvarg{line\_count}{Number of scanlines for the image.}
93 \cvarg{img}{Image to prewarp.}
94 \cvarg{dst}{Data to store for the prewarp image.}
95 \cvarg{dst\_nums}{Pointer to the array of the lengths of the scanlines.}
96 \cvarg{scanlines}{Pointer to the array of the coordinates of the scanlines.}
97 \end{description}
98
99 The function \texttt{cvPreWarpImage} rectifies an image so that the scanlines in the rectified image are horizontal. The output buffer of size \texttt{max(width,height)*line\_count*3} must be allocated before calling the function.
100
101 \cvfunc{FindRuns}
102
103 Retrieves the scanlines from a rectified image and breaks them down into runs.
104
105 \cvexp{
106 void cvFindRuns( \par int line\_count, \par uchar* prewarp1, \par uchar* prewarp2,
107                  \par int* line\_lengths1, \par int* line\_lengths2,
108                  \par int* runs1, \par int* runs2,
109                  \par int* num\_runs1, \par int* num\_runs2 );
110
111 }{CPP}{PYTHON}
112
113 \begin{description}
114 \cvarg{line\_count}{Number of scanlines.}
115 \cvarg{prewarp1}{Prewarp data of the first image.}
116 \cvarg{prewarp2}{Prewarp data of the second image.}
117 \cvarg{line\_lengths1}{Array of the lengths of the scanlines in the first image.}
118 \cvarg{line\_lengths2}{Array of the lengths of the scanlines in the second image.}
119 \cvarg{runs1}{Array of the runs in each scanline in the first image.}
120 \cvarg{runs2}{Array of the runs in each scanline in the second image.}
121 \cvarg{num\_runs1}{Array of the number of runs in each scanline in the first image.}
122 \cvarg{num\_runs2}{Array of the number of runs in each scanline in the second image.}
123 \end{description}
124
125 The function \texttt{cvFindRuns} retrieves scanlines from the rectified image and breaks each scanline down into several runs, that is, a series of pixels of almost the same brightness.
126
127 \cvfunc{DynamicCorrespondMulti}
128
129 Finds the correspondence between two sets of runs of two warped images.
130
131 \cvexp{
132 void cvDynamicCorrespondMulti( \par int line\_count, \par int* first, \par int* first\_runs,
133                                \par int* second, \par int* second\_runs,
134                                \par int* first\_corr, \par int* second\_corr );
135
136 }{CPP}{PYTHON}
137
138 \begin{description}
139 \cvarg{line\_count}{Number of scanlines.}
140 \cvarg{first}{Array of the runs in the first image.}
141 \cvarg{first\_runs}{Array of the number of runs in each scanline of the first image.}
142 \cvarg{second}{Array of the runs in the second image.}
143 \cvarg{second\_runs}{Array of the number of runs in each scanline of the second image.}
144 \cvarg{first\_corr}{Pointer to the array of the correspondence information found for the first runs.}
145 \cvarg{second\_corr}{Pointer to the array of the correspondence information found for the second runs.}
146 \end{description}
147
148 The function \texttt{cvDynamicCorrespondMulti} finds the correspondence between two sets of runs of two images. Memory must be allocated before calling this function. Memory size for one array of correspondence information is
149
150 \texttt{max( width,height )* numscanlines*3*sizeof ( int ).} 
151
152
153 \cvfunc{MakeAlphaScanlines}
154
155 Calculates the coordinates of the scanlines in an image from a virtual camera.
156
157 \cvexp{
158 void cvMakeAlphaScanlines( \par int* scanlines1, \par int* scanlines2,
159                            \par int* scanlinesA, \par int* lengths,
160                            \par int line\_count, \par float alpha );
161
162 }{CPP}{PYTHON}
163
164 \begin{description}
165 \cvarg{scanlines1}{Pointer to the array of the first scanlines.}
166 \cvarg{scanlines2}{Pointer to the array of the second scanlines.}
167 \cvarg{scanlinesA}{Pointer to the array of the scanlines found in the virtual image.}
168 \cvarg{lengths}{Pointer to the array of the lengths of the scanlines found in the virtual image.}
169 \cvarg{line\_count}{Number of scanlines.}
170 \cvarg{alpha}{Position of virtual camera \texttt{(0.0 - 1.0)}.} 
171 \end{description}
172
173 The function \texttt{cvMakeAlphaScanlines} finds the coordinates of the scanlines for the virtual camera with the given camera position.
174
175 Memory must be allocated before calling this function. Memory size for the array of correspondence runs is \texttt{numscanlines*2*4*sizeof(int)}. Memory size for the array of the scanline lengths is \texttt{numscanlines*2*4*sizeof(int).}
176
177 \cvfunc{MorphEpilinesMulti}
178
179 Morphs two pre-warped images using information about their stereo correspondence.
180
181 \cvexp{
182 void cvMorphEpilinesMulti( \par int line\_count, \par uchar* first\_pix, \par int* first\_num,
183                            \par uchar* second\_pix, \par int* second\_num,
184                            \par uchar* dst\_pix, \par int* dst\_num,
185                            \par float alpha, \par int* first, \par int* first\_runs,
186                            \par int* second, \par int* second\_runs,
187                            \par int* first\_corr, \par int* second\_corr );
188
189 }{CPP}{PYTHON}
190
191 \begin{description}
192 \cvarg{line\_count}{Number of scanlines in the prewarp image.}
193 \cvarg{first\_pix}{Pointer to the first prewarp image.}
194 \cvarg{first\_num}{Pointer to the array of the number of points in each scanline in the first image.}
195 \cvarg{second\_pix}{Pointer to the second prewarp image.}
196 \cvarg{second\_num}{Pointer to the array of the number of points in each scanline in the second image.}
197 \cvarg{dst\_pix}{Pointer to the resulting morphed warped image.}
198 \cvarg{dst\_num}{Pointer to the array of the number of points in each line.}
199 \cvarg{alpha}{Virtual camera position \texttt{(0.0 - 1.0)}.}
200 \cvarg{first}{First sequence of runs.}
201 \cvarg{first\_runs}{Pointer to the number of runs in each scanline in the first image.}
202 \cvarg{second}{Second sequence of runs.}
203 \cvarg{second\_runs}{Pointer to the number of runs in each scanline in the second image.}
204 \cvarg{first\_corr}{Pointer to the array of the correspondence information found for the first runs.}
205 \cvarg{second\_corr}{Pointer to the array of the correspondence information found for the second runs.}
206 \end{description}
207
208 The function \texttt{cvMorphEpilinesMulti} morphs two pre-warped images using information about the correspondence between the scanlines of the two images.
209
210 \cvfunc{PostWarpImage}
211
212 Warps a rectified, morphed image back.
213
214 \cvexp{
215 void cvPostWarpImage( \par int line\_count, \par uchar* src, \par int* src\_nums,
216                       \par IplImage* img, \par int* scanlines );
217
218 }{CPP}{PYTHON}
219
220 \begin{description}
221 \cvarg{line\_count}{Number of scanlines.}
222 \cvarg{src}{Pointer to the prewarp image virtual image.}
223 \cvarg{src\_nums}{Number of scanlines in the image.}
224 \cvarg{img}{Resulting unwarped image.}
225 \cvarg{scanlines}{Pointer to the array of the scanlines data.}
226 \end{description}
227
228 The function \texttt{cvPostWarpImage} warps the resultant image from the virtual camera by storing its rows across the scanlines whose coordinates are calculated by \cross{MakeAlphaScanlines}.
229
230 \cvfunc{DeleteMoire}
231
232 Deletes moire in a given image.
233
234 \cvexp{
235 void cvDeleteMoire( IplImage* img );
236
237 }{CPP}{PYTHON}
238
239 \begin{description}
240 \cvarg{img}{Image.}
241 \end{description}
242
243 The function \texttt{cvDeleteMoire} deletes moire from the given image. The post-warped image may have black (un-covered) points because of possible holes between neighboring scanlines. The function deletes moire (black pixels) from the image by substituting neighboring pixels for black pixels. If all the scanlines are horizontal, the function may be omitted.
244
245 \section{3D Tracking Functions} % XXX Weird URL Formatting, /../?
246
247 The section discusses functions for tracking objects in 3d space using a stereo camera. Besides C API, there is the DirectShow filter
248
249 \href{http://opencvlibrary.sourceforge.net/../appPage/3dTracker/3dTrackerFilter.htm}{http://opencvlibrary.sourceforge.net/../appPage/3dTracker/3dTrackerFilter.htm}
250
251 and the wrapper application.
252
253 \href{http://opencvlibrary.sourceforge.net/../appPage/3dTracker/3dTracker.htm}{http://opencvlibrary.sourceforge.net/../appPage/3dTracker/3dTracker.htm}
254
255 \href{http://opencvlibrary.sourceforge.net/../appPage/3dTracker/3dTrackerTesting.htm}{http://opencvlibrary.sourceforge.net/../appPage/3dTracker/3dTrackerTesting.htm} 
256
257 contains a description of how to test the filter on sample data.
258
259 \cvfunc{3dTrackerCalibrateCameras} % XXX URL Formatting
260
261 Simultaneously determines the position and orientation of multiple cameras.
262
263 \cvexp{
264 CvBool cv3dTrackerCalibrateCameras(\par int num\_cameras,
265            \par const Cv3dTrackerCameraIntrinsics camera\_intrinsics[],
266            \par CvSize checkerboard\_size,
267            \par IplImage *samples[],
268            \par Cv3dTrackerCameraInfo camera\_info[]);
269
270 }{CPP}{PYTHON}
271
272 \begin{description}
273 \cvarg{num\_cameras}{the number of cameras to calibrate. This is the size of each of the three array parameters.}
274 \cvarg{camera\_intrinsics}{camera intrinsics for each camera, as determined by \cross{CalibFilter}.}
275 \cvarg{checkerboard\_size}{the width and height (in number of squares) of the checkerboard.}
276 \cvarg{samples}{images from each camera, with a view of the checkerboard.}
277 \cvarg{camera\_info}{filled in with the results of the camera calibration. This is passed into \cross{3dTrackerLocateObjects} to do tracking.}
278 \end{description}
279
280 The function \texttt{cv3dTrackerCalibrateCameras} searches for a checkerboard of the specified size in each of the images. For each image in which it finds the checkerboard, it fills in the corresponding slot in \texttt{camera\_info} with the position and orientation of the camera relative to the checkerboard and sets the \texttt{valid} flag. If it finds the checkerboard in all the images, it returns true; otherwise it returns false.
281
282 This function does not change the members of the \texttt{camera\_info} array that correspond to images in which the checkerboard was not found. This allows you to calibrate each camera independently, instead of simultaneously. To accomplish this, do the following:
283 \begin{enumerate}
284 \item Clear all the \texttt{valid} flags before calling this function the first time;
285 \item Call this function with each set of images;
286 \item Check all the \texttt{valid} flags after each call. When all the \texttt{valid} flags are set, calibration is complete.
287 \end{enumerate}
288
289 Note that this method works well only if the checkerboard is rigidly mounted; if it is handheld, all the cameras should be calibrated simultanously to get an accurate result. To ensure that all cameras are calibrated simultaneously, ignore the \texttt{valid} flags and use the return value to decide when calibration is complete.
290
291 \cvfunc{3dTrackerLocateObjects}
292
293 Determines the 3d location of tracked objects.
294
295 \cvexp{
296 int  cv3dTrackerLocateObjects(\par int num\_cameras,
297          \par int num\_objects,
298          \par const Cv3dTrackerCameraInfo camera\_info[],
299          \par const Cv3dTracker2dTrackedObject tracking\_info[],
300          \par Cv3dTrackerTrackedObject tracked\_objects[]);
301
302 }{CPP}{PYTHON}
303
304 \begin{description}
305 \cvarg{num\_cameras}{the number of cameras.}
306 \cvarg{num\_objects}{the maximum number of objects found by any camera. (Also the maximum number of objects returned in \texttt{tracked\_objects}.}
307 \cvarg{camera\_info}{camera position and location information for each camera, as determined by \newline \cross{3dTrackerCalibrateCameras}.}
308 \cvarg{tracking\_info}{the 2d position of each object as seen by each camera. Although this is specified as a one-dimensional array, it is actually a two-dimensional array: \texttt{const \newline Cv3dTracker2dTrackedObject tracking\_info[num\_cameras][num\_objects]}. The \texttt{id} field of any unused slots must be -1. Ids need not be ordered or consecutive.}
309 \cvarg{tracked\_objects}{filled in with the results.}
310 \end{description}
311
312 The function \texttt{cv3dTrackerLocateObjects} determines the 3d position of tracked objects based on the 2d tracking information from multiple cameras and the camera position and orientation information computed by \cross{3dTrackerCalibrateCameras}. It locates any objects with the same \texttt{id} that are tracked by more than one camera. It fills in the \texttt{tracked\_objects} array and returns the number of objects located. The \texttt{id} fields of any unused slots in \texttt{tracked\_objects} are set to -1.
313
314 \section{Eigen Objects (PCA) Functions}
315
316 The functions described in this section do PCA analysis
317 and compression for a set of 8-bit images that may not fit
318 into memory all together. If your data fits into memory and
319 the vectors are not 8-bit (or you want a simpler interface), use
320 \cross{CalcCovarMatrix},
321 \cross{SVD}
322 and
323 \cross{GEMM}
324 to do PCA.
325
326 \cvfunc{CalcCovarMatrixEx}
327
328 Calculates the covariance matrix for a group of input objects.
329
330 \cvexp{
331 void cvCalcCovarMatrixEx( \par int object\_count, \par void* input, \par int io\_flags,
332                           \par int iobuf\_size, \par uchar* buffer, \par void* userdata,
333                           \par IplImage* avg, \par float* covar\_matrix );
334
335 }{CPP}{PYTHON}
336
337 \begin{description}
338 \cvarg{object\_count}{Number of source objects.}
339 \cvarg{input}{Pointer either to the array of \texttt{IplImage} input objects or to the read callback function according to the value of the parameter \texttt{ioFlags}.}
340 \cvarg{io\_flags}{Input/output flags.}
341 \cvarg{iobuf\_size}{Input/output buffer size.}
342 \cvarg{buffer}{Pointer to the input/output buffer.}
343 \cvarg{userdata}{Pointer to the structure that contains all necessary data for the callback functions.}
344 \cvarg{avg}{Averaged object.}
345 \cvarg{covar\_matrix}{Covariance matrix. An output parameter; must be allocated before the call.}
346 \end{description}
347
348 The function \texttt{cvCalcCovarMatrixEx} calculates a covariance matrix of the input objects group using a previously calculated averaged object. Depending on the \texttt{ioFlags} parameter it may be used either in direct access or callback mode. If \texttt{ioFlags} is not \texttt{CV\_EIGOBJ\_NO\_CALLBACK}, the buffer must be allocated before calling the function.
349
350 \cvfunc{CalcEigenObjects}
351
352 Calculates the orthonormal eigen basis and the averaged object for group a of input objects.
353
354 \cvexp{
355 void cvCalcEigenObjects( \par int nObjects, \par void* input, \par void* output, \par int ioFlags,
356                          \par int ioBufSize, \par void* userData, \par CvTermCriteria* calcLimit,
357                          \par IplImage* avg, \par float* eigVals );
358
359 }{CPP}{PYTHON}
360
361 \begin{description}
362 \cvarg{nObjects}{Number of source objects.}
363 \cvarg{input}{Pointer either to the array of \texttt{IplImage} input objects or to the read callback function according to the value of the parameter \texttt{ioFlags}.}
364 \cvarg{output}{Pointer either to the array of eigen objects or to the write callback function according to the value of the parameter ioFlags.}
365 \cvarg{ioFlags}{Input/output flags.}
366 \cvarg{ioBufSize}{Input/output buffer size in bytes. The size is zero if unknown.}
367 \cvarg{userData}{Pointer to the structure that contains all of the necessary data for the callback functions.}
368 \cvarg{calcLimit}{Criteria that determine when to stop the calculation of eigen objects.}
369 \cvarg{avg}{Averaged object.}
370 \cvarg{eigVals}{Pointer to the eigenvalues array in the descending order; may be \texttt{NULL}.}
371 \end{description}
372
373 The function \texttt{cvCalcEigenObjects} calculates the orthonormal eigen basis and the averaged object for a group of input objects. Depending on the \texttt{ioFlags} parameter it may be used either in direct access or callback mode. Depending on the parameter \texttt{calcLimit}, calculations are finished either after the first \texttt{calcLimit.max\_iter} dominating eigen objects are retrieved or if the ratio of the current eigenvalue to the largest eigenvalue comes down to the \texttt{calcLimit.epsilon} threshold. The value \texttt{calcLimit -> type} must be \texttt{CV\_TERMCRIT\_NUMB, CV\_TERMCRIT\_EPS}, or \texttt{CV\_TERMCRIT\_NUMB | CV\_TERMCRIT\_EPS} . The function returns the real values \texttt{calcLimit->max\_iter} and \texttt{calcLimit->epsilon} .
374
375 The function also calculates the averaged object, which must be created previously. Calculated eigen objects are arranged according to the corresponding eigenvalues in descending order.
376
377 The parameter \texttt{eigVals} may be equal to \texttt{NULL} if eigenvalues are not needed.
378
379 The function \texttt{cvCalcEigenObjects} uses the function \cross{cvCalcCovarMatrixEx}.
380
381 \cvfunc{CalcDecompCoeff}
382
383 Calculates the decomposition coefficient of an input object.
384
385 \cvexp{
386 double cvCalcDecompCoeff( \par IplImage* obj, \par IplImage* eigObj, \par IplImage* avg );
387
388 }{CPP}{PYTHON}
389
390 \begin{description}
391 \cvarg{obj}{Input object.}
392 \cvarg{eigObj}{Eigen object.}
393 \cvarg{avg}{Averaged object.}
394 \end{description}
395
396 The function \texttt{cvCalcDecompCoeff} calculates one decomposition coefficient of the input object using the previously calculated eigen object and the averaged object.
397
398 \cvfunc{EigenDecomposite}
399
400 Calculates all of the decomposition coefficients for an input object.
401
402 \cvexp{
403 void cvEigenDecomposite( \par IplImage* obj, \par int eigenvec\_count, \par void* eigInput,
404                          \par int ioFlags, \par void* userData, \par IplImage* avg, \par float* coeffs );
405
406 }{CPP}{PYTHON}
407
408 \begin{description}
409 \cvarg{obj}{Input object.}
410 \cvarg{eigenvec\_count}{Number of eigen objects.}
411 \cvarg{eigInput}{Pointer either to the array of \texttt{IplImage} input objects or to the read callback function according to the value of the parameter \texttt{ioFlags}.}
412 \cvarg{ioFlags}{Input/output flags.}
413 \cvarg{userData}{Pointer to the structure that contains all of the necessary data for the callback functions.}
414 \cvarg{avg}{Averaged object.}
415 \cvarg{coeffs}{Calculated coefficients; an output parameter.}
416 \end{description}
417
418 The function \texttt{cvEigenDecomposite} calculates all of the decomposition coefficients for the input object using the previously calculated eigen objects basis and the averaged object. Depending on the \texttt{ioFlags} parameter it may be used either in direct access or callback mode.
419
420 \cvfunc{EigenProjection}
421
422 Calculates the object projection into the eigen sub-space.
423
424 \cvexp{
425 void cvEigenProjection( \par void* input\_vecs, \par int eigenvec\_count, \par int io\_flags, \par void* userdata,
426                         \par float* coeffs, \par IplImage* avg, \par IplImage* proj );
427
428 }{CPP}{PYTHON}
429
430 \begin{description}
431 \cvarg{input\_vec}{Pointer to either an array of \texttt{IplImage} input objects or to a callback function, depending on \texttt{io\_flags}.}
432 \cvarg{eigenvec\_count}{Number of eigenvectors.}
433 \cvarg{io\_flags}{Input/output flags; see \cross{cvCalcEigenObjects}.}
434 \cvarg{userdata}{Pointer to the structure that contains all of the necessary data for the callback functions.}
435 \cvarg{coeffs}{Previously calculated decomposition coefficients.}
436 \cvarg{avg}{Average vector, calculated by \cross{cvCalcEigenObjects}.}
437 \cvarg{proj}{Projection to the eigen sub-space.}
438 \end{description}
439
440 The function \texttt{cvEigenProjection} calculates an object projection to the eigen sub-space or, in other words, restores an object using previously calculated eigen objects basis, averaged object, and the decomposition coefficients of the restored object. Depending on the \texttt{io\_flags} parameter it may be used either in direct access or callback mode.
441
442 \section{Embedded Hidden Markov Models Functions}
443
444 In order to support embedded models, the user must define structures to represent a 1D HMM and a 2D embedded HMM model.
445
446 \cvfunc{CvHMM} 
447
448 Embedded HMM Structure.
449
450 \cvexp{typedef struct \_CvEHMM}{CPP}{PYTHON}
451 \begin{lstlisting} 
452     {
453         int level;
454         int num_states;
455         float* transP;
456         float** obsProb;
457         union
458         {
459             CvEHMMState* state;
460             struct _CvEHMM* ehmm;
461         } u;
462     } CvEHMM;
463 \end{lstlisting}
464
465
466 \begin{description}
467 \cvarg{level}{Level of embedded HMM. If \texttt{level ==0}, HMM is mostly external. In 2D HMM there are two types of HMM: 1 external and several embedded. External HMM has \texttt{level ==1}, embedded HMMs have \texttt{level ==0}.}
468 \cvarg{num\_states}{Number of states in 1D HMM.}
469 \cvarg{transP}{State-to-state transition probability, square matrix \texttt{(num\_state×num\_state )}.}
470 \cvarg{obsProb}{Observation probability matrix.}
471 \cvarg{state}{Array of HMM states. For the last-level HMM, that is, an HMM without embedded HMMs, HMM states are real.}
472 \cvarg{ehmm}{Array of embedded HMMs. If HMM is not last-level, then HMM states are not real and they are HMMs.}
473 \end{description}
474
475 For representation of observations the following structure is defined:
476
477 \cvfunc{CvImgObsInfo}
478
479 Image Observation Structure.
480
481 \cvexp{
482     typedef struct CvImgObsInfo
483     }{CPP}{PYTHON}
484 \begin{lstlisting}
485     {
486         int obs_x;
487         int obs_y;
488         int obs_size;
489         float** obs;
490         int* state;
491         int* mix;
492     } CvImgObsInfo;
493 \end{lstlisting}
494
495 \begin{description}
496 \cvarg{obs\_x}{Number of observations in the horizontal direction.}
497 \cvarg{obs\_y}{Number of observations in the vertical direction.}
498 \cvarg{obs\_size}{Length of each observation vector.}
499 \cvarg{obs}{Pointer to the observation vectors stored consequently. Number of vectors is \texttt{obs\_x*obs\_y}.}
500 \cvarg{state}{Array of indices of states, assigned to every observation vector.}
501 \cvarg{mix}{Index of mixture component, corresponding to the observation vector within an assigned state.}
502 \end{description}
503
504 \cvfunc{Create2DHMM}
505
506 Creates a 2D, embedded HMM.
507
508 \cvexp{
509 CvEHMM* cvCreate2DHMM( int* stateNumber, int* numMix, int obsSize );
510
511 }{CPP}{PYTHON}
512
513 \begin{description}
514 \cvarg{stateNumber}{Array, the first element of which specifies the number of superstates in the HMM. All of the subsequent elements specify the number of states in every embedded HMM, corresponding to each superstate. So, the length of the array is \texttt{stateNumber [0]+1}.}
515 \cvarg{numMix}{Array with numbers of Gaussian mixture components for each internal state. The number of elements in the array is equal to number of internal states in the HMM, that is, superstates are not counted here.}
516 \cvarg{obsSize}{Size of the observation vectors to be used with created HMM.}
517 \end{description}
518
519 The function \texttt{cvCreate2DHMM} returns the created structure of the type \cross{CvEHMM} with the specified parameters.
520
521 \cvfunc{Release2DHMM}
522  
523 Releases a 2D, embedded HMM.
524
525 \cvexp{
526 void cvRelease2DHMM(CvEHMM** hmm );
527
528 }{CPP}{PYTHON}
529
530 \begin{description}
531 \cvarg{hmm}{Address of the pointer to the HMM to be released.}
532 \end{description}
533
534 The function \texttt{cvRelease2DHMM} frees all the memory used by the HMM and clears the pointer to the HMM.
535
536 \cvfunc{CreateObsInfo}
537
538 Creates a structure to store image observation vectors.
539
540 \cvexp{
541 CvImgObsInfo* cvCreateObsInfo( CvSize numObs, int obsSize );
542
543 }{CPP}{PYTHON}
544
545 \begin{description}
546 \cvarg{numObs}{Numbers of observations in the horizontal and vertical directions. For the given image and scheme of extracting observations the parameter can be computed via the macro \texttt{CV\_COUNT\_OBS( roi, dctSize, delta, numObs )}, where \texttt{roi, dctSize, delta, numObs} are the pointers to structures of the type \cross{CvSize}. The pointer \texttt{roi} means the size of \texttt{roi} of the image observed, \texttt{numObs} is the output parameter of the macro.}
547 \cvarg{obsSize}{Size of the observation vectors to be stored in the structure.}
548 \end{description}
549
550 The function \texttt{cvCreateObsInfo} creates new structures to store image observation vectors. For definitions of the parameters \texttt{roi, dctSize}, and \texttt{delta} see the specification of the function \texttt{cvImgToObs\_DCT}.
551
552 \cvfunc{ReleaseObsInfo}
553
554 Releases the observation vector structures.
555
556 \cvexp{
557 void cvReleaseObsInfo( CvImgObsInfo** obsInfo );
558
559 }{CPP}{PYTHON}
560
561 \begin{description}
562 \cvarg{obsInfo}{Address of the pointer to the structure \cross{CvImgObsInfo}.}
563 \end{description}
564
565 The function \texttt{cvReleaseObsInfo} frees all of the memory used by the observations and clears the pointer to the structure \cross{CvImgObsInfo}.
566
567 \cvfunc{ImgToObs\_DCT}
568
569 Extracts observation vectors from an image.
570
571 \cvexp{
572 void cvImgToObs\_DCT( \par IplImage* image, \par float* obs, \par CvSize dctSize,
573                      \par CvSize obsSize, \par CvSize delta );
574
575 }{CPP}{PYTHON}
576
577 \begin{description}
578 \cvarg{image}{Input image.}
579 \cvarg{obs}{Pointer to the consequently stored observation vectors.}
580 \cvarg{dctSize}{Size of the image blocks for which the DCT (Discrete Cosine Transform) coefficients are to be computed.}
581 \cvarg{obsSize}{Number of the lowest DCT coefficients in the horizontal and vertical directions to be put into the observation vector.}
582 \cvarg{delta}{Shift in pixels between two consecutive image blocks in the horizontal and vertical directions.}
583 \end{description}
584
585 The function \texttt{cvImgToObs\_DCT} extracts observation vectors, that is, DCT coefficients, from the image. The user must pass \texttt{obsInfo.obs} as the parameter \texttt{obs} to use this function with other HMM functions and use the structure \texttt{obsInfo} of the \cross{CvImgObsInfo} type.
586
587
588 \texttt{Calculating Observations for HMM}
589
590 \cvexp{
591     CvImgObsInfo* obs\_info;
592
593         ...
594
595         cvImgToObs\_DCT( image,obs\_info->obs, //!!!
596
597         dctSize, obsSize, delta );
598
599 }{CPP}{PYTHON}
600
601 \cvfunc{UniformImgSegm} 
602
603 Performs uniform segmentation of image observations using HMM states.
604
605 \cvexp{
606 void cvUniformImgSegm( CvImgObsInfo* obsInfo, CvEHMM* hmm );
607
608 }{CPP}{PYTHON}
609
610 \begin{description}
611 \cvarg{obsInfo}{Observation structures.}
612 \cvarg{hmm}{HMM structure.}
613 \end{description}
614
615 The function \texttt{cvUniformImgSegm} segments image observations using HMM states uniformly (see \textcolor{blue}{\underline{Initial Segmentation}} for 2D Embedded HMM for 2D embedded HMM with 5 superstates and 3, 6, 6, 6, 3 internal states of every corresponding superstate).
616
617 \textcolor{blue}{Initial Segmentation for 2D Embedded HMM}
618
619 \includegraphics{pics/face.png}
620
621 \cvfunc{InitMixSegm}
622
623 Segments all observations within every internal state of HMM using state mixture components.
624
625 \cvexp{
626 void cvInitMixSegm( \par CvImgObsInfo** obsInfoArray, \par int numImg, \par CvEHMM* hmm );
627
628 }{CPP}{PYTHON}
629
630 \begin{description}
631 \cvarg{obsInfoArray}{Array of pointers to the observation structures.}
632 \cvarg{numImg}{Length of the above array.}
633 \cvarg{hmm}{HMM.}
634 \end{description}
635
636 The function \texttt{cvInitMixSegm} takes a group of observations from several training images already segmented by states and splits a set of observation vectors within every internal HMM state into as many clusters as the number of mixture components in the state.
637
638 \cvfunc{EstimateHMMStateParams}
639
640 Estimates all of the parameters of every HMM state.
641
642 \cvexp{
643 void cvEstimateHMMStateParams( \par CvImgObsInfo** obsInfoArray, \par int numImg, \par CvEHMM* hmm );
644
645 }{CPP}{PYTHON}
646
647 \begin{description}
648 \cvarg{obsInfoArray}{Array of pointers to the observation structures.}
649 \cvarg{numImg}{Length of the array.}
650 \cvarg{hmm}{HMM.}
651 \end{description}
652
653 The function \texttt{cvEstimateHMMStateParams} computes all inner parameters of every HMM state, including Gaussian means, variances, and so forth.
654
655 \cvfunc{EstimateTransProb}
656
657 Computes transition probability matrices for the embedded HMM.
658
659 \cvexp{
660 void cvEstimateTransProb( \par CvImgObsInfo** obsInfoArray, \par int numImg, \par CvEHMM* hmm );
661
662 }{CPP}{PYTHON}
663
664 \begin{description}
665 \cvarg{obsInfoArray}{Array of pointers to the observation structures.}
666 \cvarg{numImg}{Length of the above array.}
667 \cvarg{hmm}{HMM.}
668 \end{description}
669
670 The function \texttt{cvEstimateTransProb} uses the current segmentation of image observations to compute the transition probability matrices for all embedded and external HMMs.
671
672 \cvfunc{EstimateObsProb}
673
674 Computes the probability of every observation of several images.
675
676 \cvexp{
677 void cvEstimateObsProb( CvImgObsInfo* obsInfo, CvEHMM* hmm );
678
679 }{CPP}{PYTHON}
680
681 \begin{description}
682 \cvarg{obsInfo}{Observation structure.}
683 \cvarg{hmm}{HMM structure.}
684 \end{description}
685
686 The function \texttt{cvEstimateObsProb} computes the Gaussian probabilities of each observation to occur in each of the internal HMM states.
687
688 \cvfunc{EViterbi}
689
690 Executes the Viterbi algorithm for the embedded HMM.
691
692 \cvexp{
693 float cvEViterbi( CvImgObsInfo* obsInfo, CvEHMM* hmm );
694
695 }{CPP}{PYTHON}
696
697 \begin{description}
698 \cvarg{obsInfo}{Observation structure.
699 }\cvarg{hmm}{HMM structure.}
700 \end{description}
701
702 The function \texttt{cvEViterbi} executes the Viterbi algorithm for the embedded HMM. The Viterbi algorithm evaluates the likelihood of the best match between the given image observations and the given HMM and performs segmentation of image observations by HMM states. The segmentation is done on the basis of the match found.
703
704 \cvfunc{MixSegmL2}
705
706 Segments the observations from all of the training images using the mixture components of the newly assigned states.
707
708 \cvexp{
709 void cvMixSegmL2( \par CvImgObsInfo** obsInfoArray, \par int numImg, \par CvEHMM* hmm );
710
711 }{CPP}{PYTHON}
712
713 \begin{description}
714 \cvarg{obsInfoArray}{Array of pointers to the observation structures.}
715 \cvarg{numImg}{Length of the array.}
716 \cvarg{hmm}{HMM.}
717 \end{description}
718
719 The function \texttt{cvMixSegmL2} segments the observations from all of the training images using the mixture components of the newly Viterbi algorithm-assigned states. The function uses the Euclidean distance to group vectors around the existing mixtures centers.
720