1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
10 // Intel License Agreement
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
19 // * Redistribution's of source code must retain the above copyright notice,
20 // this list of conditions and the following disclaimer.
22 // * Redistribution's in binary form must reproduce the above copyright notice,
23 // this list of conditions and the following disclaimer in the documentation
24 // and/or other materials provided with the distribution.
26 // * The name of Intel Corporation may not be used to endorse or promote products
27 // derived from this software without specific prior written permission.
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
45 * support functions for training and test samples creation.
48 #include "cvhaartraining.h"
49 #include "_cvhaartraining.h"
51 /* if ipl.h file is included then iplWarpPerspectiveQ function
52 is used for image transformation during samples creation;
53 otherwise internal cvWarpPerspective function is used */
60 /* Calculates coefficients of perspective transformation
61 * which maps <quad> into rectangle ((0,0), (w,0), (w,h), (h,0)):
63 * c00*xi + c01*yi + c02
64 * ui = ---------------------
65 * c20*xi + c21*yi + c22
67 * c10*xi + c11*yi + c12
68 * vi = ---------------------
69 * c20*xi + c21*yi + c22
71 * Coefficients are calculated by solving linear system:
72 * / x0 y0 1 0 0 0 -x0*u0 -y0*u0 \ /c00\ /u0\
73 * | x1 y1 1 0 0 0 -x1*u1 -y1*u1 | |c01| |u1|
74 * | x2 y2 1 0 0 0 -x2*u2 -y2*u2 | |c02| |u2|
75 * | x3 y3 1 0 0 0 -x3*u3 -y3*u3 |.|c10|=|u3|,
76 * | 0 0 0 x0 y0 1 -x0*v0 -y0*v0 | |c11| |v0|
77 * | 0 0 0 x1 y1 1 -x1*v1 -y1*v1 | |c12| |v1|
78 * | 0 0 0 x2 y2 1 -x2*v2 -y2*v2 | |c20| |v2|
79 * \ 0 0 0 x3 y3 1 -x3*v3 -y3*v3 / \c21/ \v3/
82 * (xi, yi) = (quad[i][0], quad[i][1])
83 * cij - coeffs[i][j], coeffs[2][2] = 1
84 * (ui, vi) - rectangle vertices
86 static void cvGetPerspectiveTransform( CvSize src_size, double quad[4][2],
89 //CV_FUNCNAME( "cvWarpPerspective" );
96 CvMat A = cvMat( 8, 8, CV_64FC1, a );
97 CvMat B = cvMat( 8, 1, CV_64FC1, b );
98 CvMat X = cvMat( 8, 1, CV_64FC1, coeffs );
101 for( i = 0; i < 4; ++i )
103 a[i][0] = quad[i][0]; a[i][1] = quad[i][1]; a[i][2] = 1;
104 a[i][3] = a[i][4] = a[i][5] = a[i][6] = a[i][7] = 0;
107 for( i = 4; i < 8; ++i )
109 a[i][3] = quad[i-4][0]; a[i][4] = quad[i-4][1]; a[i][5] = 1;
110 a[i][0] = a[i][1] = a[i][2] = a[i][6] = a[i][7] = 0;
114 int u = src_size.width - 1;
115 int v = src_size.height - 1;
117 a[1][6] = -quad[1][0] * u; a[1][7] = -quad[1][1] * u;
118 a[2][6] = -quad[2][0] * u; a[2][7] = -quad[2][1] * u;
121 a[6][6] = -quad[2][0] * v; a[6][7] = -quad[2][1] * v;
122 a[7][6] = -quad[3][0] * v; a[7][7] = -quad[3][1] * v;
125 cvSolve( &A, &B, &X );
132 /* Warps source into destination by a perspective transform */
133 static void cvWarpPerspective( CvArr* src, CvArr* dst, double quad[4][2] )
135 CV_FUNCNAME( "cvWarpPerspective" );
140 IplImage src_stub, dst_stub;
143 CV_CALL( src_img = cvGetImage( src, &src_stub ) );
144 CV_CALL( dst_img = cvGetImage( dst, &dst_stub ) );
145 iplWarpPerspectiveQ( src_img, dst_img, quad, IPL_WARP_R_TO_Q,
146 IPL_INTER_CUBIC | IPL_SMOOTH_EDGE );
151 double c[3][3]; /* transformation coefficients */
152 double q[4][2]; /* rearranged quad */
160 double k_left, b_left, k_right, b_right;
174 if( !src || (!CV_IS_IMAGE( src ) && !CV_IS_MAT( src )) ||
175 cvGetElemType( src ) != CV_8UC1 ||
176 cvGetDims( src ) != 2 )
178 CV_ERROR( CV_StsBadArg,
179 "Source must be two-dimensional array of CV_8UC1 type." );
181 if( !dst || (!CV_IS_IMAGE( dst ) && !CV_IS_MAT( dst )) ||
182 cvGetElemType( dst ) != CV_8UC1 ||
183 cvGetDims( dst ) != 2 )
185 CV_ERROR( CV_StsBadArg,
186 "Destination must be two-dimensional array of CV_8UC1 type." );
189 CV_CALL( cvGetRawData( src, &src_data, &src_step, &src_size ) );
190 CV_CALL( cvGetRawData( dst, &dst_data, &dst_step, &dst_size ) );
192 CV_CALL( cvGetPerspectiveTransform( src_size, quad, c ) );
194 /* if direction > 0 then vertices in quad follow in a CW direction,
195 otherwise they follow in a CCW direction */
197 for( i = 0; i < 4; ++i )
199 int ni = i + 1; if( ni == 4 ) ni = 0;
200 int pi = i - 1; if( pi == -1 ) pi = 3;
202 d = (quad[i][0] - quad[pi][0])*(quad[ni][1] - quad[i][1]) -
203 (quad[i][1] - quad[pi][1])*(quad[ni][0] - quad[i][0]);
204 int cur_direction = CV_SIGN(d);
207 direction = cur_direction;
209 else if( direction * cur_direction < 0 )
217 CV_ERROR( CV_StsBadArg, "Quadrangle is nonconvex or degenerated." );
220 /* <left> is the index of the topmost quad vertice
221 if there are two such vertices <left> is the leftmost one */
223 for( i = 1; i < 4; ++i )
225 if( (quad[i][1] < quad[left][1]) ||
226 ((quad[i][1] == quad[left][1]) && (quad[i][0] < quad[left][0])) )
231 /* rearrange <quad> vertices in such way that they follow in a CW
232 direction and the first vertice is the topmost one and put them
236 for( i = left; i < 4; ++i )
238 q[i-left][0] = quad[i][0];
239 q[i-left][1] = quad[i][1];
241 for( i = 0; i < left; ++i )
243 q[4-left+i][0] = quad[i][0];
244 q[4-left+i][1] = quad[i][1];
249 for( i = left; i >= 0; --i )
251 q[left-i][0] = quad[i][0];
252 q[left-i][1] = quad[i][1];
254 for( i = 3; i > left; --i )
256 q[4+left-i][0] = quad[i][0];
257 q[4+left-i][1] = quad[i][1];
262 /* if there are two topmost points, <right> is the index of the rightmost one
264 if( q[left][1] == q[left+1][1] )
269 /* <next_left> follows <left> in a CCW direction */
271 /* <next_right> follows <right> in a CW direction */
272 next_right = right + 1;
274 /* subtraction of 1 prevents skipping of the first row */
275 y_min = q[left][1] - 1;
277 /* left edge equation: y = k_left * x + b_left */
278 k_left = (q[left][0] - q[next_left][0]) /
279 (q[left][1] - q[next_left][1]);
280 b_left = (q[left][1] * q[next_left][0] -
281 q[left][0] * q[next_left][1]) /
282 (q[left][1] - q[next_left][1]);
284 /* right edge equation: y = k_right * x + b_right */
285 k_right = (q[right][0] - q[next_right][0]) /
286 (q[right][1] - q[next_right][1]);
287 b_right = (q[right][1] * q[next_right][0] -
288 q[right][0] * q[next_right][1]) /
289 (q[right][1] - q[next_right][1]);
295 y_max = MIN( q[next_left][1], q[next_right][1] );
297 int iy_min = MAX( cvRound(y_min), 0 ) + 1;
298 int iy_max = MIN( cvRound(y_max), dst_size.height - 1 );
300 double x_min = k_left * iy_min + b_left;
301 double x_max = k_right * iy_min + b_right;
303 /* walk through the destination quadrangle row by row */
304 for( y = iy_min; y <= iy_max; ++y )
306 int ix_min = MAX( cvRound( x_min ), 0 );
307 int ix_max = MIN( cvRound( x_max ), dst_size.width - 1 );
309 for( x = ix_min; x <= ix_max; ++x )
311 /* calculate coordinates of the corresponding source array point */
312 double div = (c[2][0] * x + c[2][1] * y + c[2][2]);
313 double src_x = (c[0][0] * x + c[0][1] * y + c[0][2]) / div;
314 double src_y = (c[1][0] * x + c[1][1] * y + c[1][2]) / div;
316 int isrc_x = cvFloor( src_x );
317 int isrc_y = cvFloor( src_y );
318 double delta_x = src_x - isrc_x;
319 double delta_y = src_y - isrc_y;
321 uchar* s = src_data + isrc_y * src_step + isrc_x;
323 int i00, i10, i01, i11;
324 i00 = i10 = i01 = i11 = (int) fill_value;
326 /* linear interpolation using 2x2 neighborhood */
327 if( isrc_x >= 0 && isrc_x <= src_size.width &&
328 isrc_y >= 0 && isrc_y <= src_size.height )
332 if( isrc_x >= -1 && isrc_x < src_size.width &&
333 isrc_y >= 0 && isrc_y <= src_size.height )
337 if( isrc_x >= 0 && isrc_x <= src_size.width &&
338 isrc_y >= -1 && isrc_y < src_size.height )
342 if( isrc_x >= -1 && isrc_x < src_size.width &&
343 isrc_y >= -1 && isrc_y < src_size.height )
348 double i0 = i00 + (i10 - i00)*delta_x;
349 double i1 = i01 + (i11 - i01)*delta_x;
351 ((uchar*)(dst_data + y * dst_step))[x] = (uchar) (i0 + (i1 - i0)*delta_y);
357 if( (next_left == next_right) ||
358 (next_left+1 == next_right && q[next_left][1] == q[next_right][1]) )
363 if( y_max == q[next_left][1] )
366 next_left = left - 1;
368 k_left = (q[left][0] - q[next_left][0]) /
369 (q[left][1] - q[next_left][1]);
370 b_left = (q[left][1] * q[next_left][0] -
371 q[left][0] * q[next_left][1]) /
372 (q[left][1] - q[next_left][1]);
374 if( y_max == q[next_right][1] )
377 next_right = right + 1;
379 k_right = (q[right][0] - q[next_right][0]) /
380 (q[right][1] - q[next_right][1]);
381 b_right = (q[right][1] * q[next_right][0] -
382 q[right][0] * q[next_right][1]) /
383 (q[right][1] - q[next_right][1]);
387 #endif /* #ifndef __IPL_H__ */
393 void icvRandomQuad( int width, int height, double quad[4][2],
398 double distfactor = 3.0;
399 double distfactor2 = 1.0;
404 double rotVectData[3];
406 double rotMatData[9];
414 rotVect = cvMat( 3, 1, CV_64FC1, &rotVectData[0] );
415 rotMat = cvMat( 3, 3, CV_64FC1, &rotMatData[0] );
416 vect = cvMat( 3, 1, CV_64FC1, &vectData[0] );
418 rotVectData[0] = maxxangle * (2.0 * rand() / RAND_MAX - 1.0);
419 rotVectData[1] = ( maxyangle - fabs( rotVectData[0] ) )
420 * (2.0 * rand() / RAND_MAX - 1.0);
421 rotVectData[2] = maxzangle * (2.0 * rand() / RAND_MAX - 1.0);
422 d = (distfactor + distfactor2 * (2.0 * rand() / RAND_MAX - 1.0)) * width;
425 rotVectData[0] = maxxangle;
426 rotVectData[1] = maxyangle;
427 rotVectData[2] = maxzangle;
429 d = distfactor * width;
432 cvRodrigues2( &rotVect, &rotMat );
435 halfh = 0.5 * height;
446 for( i = 0; i < 4; i++ )
448 rotVectData[0] = quad[i][0];
449 rotVectData[1] = quad[i][1];
450 rotVectData[2] = 0.0;
451 cvMatMulAdd( &rotMat, &rotVect, 0, &vect );
452 quad[i][0] = vectData[0] * d / (d + vectData[2]) + halfw;
453 quad[i][1] = vectData[1] * d / (d + vectData[2]) + halfh;
463 int icvStartSampleDistortion( const char* imgfilename, int bgcolor, int bgthreshold,
464 CvSampleDistortionData* data )
466 memset( data, 0, sizeof( *data ) );
467 data->src = cvLoadImage( imgfilename, 0 );
468 if( data->src != NULL && data->src->nChannels == 1
469 && data->src->depth == IPL_DEPTH_8U )
478 data->dx = data->src->width / 2;
479 data->dy = data->src->height / 2;
480 data->bgcolor = bgcolor;
482 data->mask = cvCloneImage( data->src );
483 data->erode = cvCloneImage( data->src );
484 data->dilate = cvCloneImage( data->src );
486 /* make mask image */
487 for( r = 0; r < data->mask->height; r++ )
489 for( c = 0; c < data->mask->width; c++ )
491 pmask = ( (uchar*) (data->mask->imageData + r * data->mask->widthStep)
493 if( bgcolor - bgthreshold <= (int) (*pmask) &&
494 (int) (*pmask) <= bgcolor + bgthreshold )
500 *pmask = (uchar) 255;
505 /* extend borders of source image */
506 cvErode( data->src, data->erode, 0, 1 );
507 cvDilate( data->src, data->dilate, 0, 1 );
508 for( r = 0; r < data->mask->height; r++ )
510 for( c = 0; c < data->mask->width; c++ )
512 pmask = ( (uchar*) (data->mask->imageData + r * data->mask->widthStep)
516 psrc = ( (uchar*) (data->src->imageData + r * data->src->widthStep)
519 ( (uchar*) (data->erode->imageData + r * data->erode->widthStep)
522 ( (uchar*)(data->dilate->imageData + r * data->dilate->widthStep)
524 de = (uchar)(bgcolor - (*perode));
525 dd = (uchar)((*pdilate) - bgcolor);
526 if( de >= dd && de > bgthreshold )
530 if( dd > de && dd > bgthreshold )
532 (*psrc) = (*pdilate);
538 data->img = cvCreateImage( cvSize( data->src->width + 2 * data->dx,
539 data->src->height + 2 * data->dy ),
541 data->maskimg = cvCloneImage( data->img );
549 void icvPlaceDistortedSample( CvArr* background,
550 int inverse, int maxintensitydev,
551 double maxxangle, double maxyangle, double maxzangle,
552 int inscribe, double maxshiftf, double maxscalef,
553 CvSampleDistortionData* data )
571 double xshift, yshift, randscale;
573 icvRandomQuad( data->src->width, data->src->height, quad,
574 maxxangle, maxyangle, maxzangle );
575 quad[0][0] += (double) data->dx;
576 quad[0][1] += (double) data->dy;
577 quad[1][0] += (double) data->dx;
578 quad[1][1] += (double) data->dy;
579 quad[2][0] += (double) data->dx;
580 quad[2][1] += (double) data->dy;
581 quad[3][0] += (double) data->dx;
582 quad[3][1] += (double) data->dy;
584 cvSet( data->img, cvScalar( data->bgcolor ) );
585 cvSet( data->maskimg, cvScalar( 0.0 ) );
587 cvWarpPerspective( data->src, data->img, quad );
588 cvWarpPerspective( data->mask, data->maskimg, quad );
590 cvSmooth( data->maskimg, data->maskimg, CV_GAUSSIAN, 3, 3 );
592 bgimg = cvGetMat( background, &stub );
596 cr.width = data->src->width;
597 cr.height = data->src->height;
601 /* quad's circumscribing rectangle */
602 cr.x = (int) MIN( quad[0][0], quad[3][0] );
603 cr.y = (int) MIN( quad[0][1], quad[1][1] );
604 cr.width = (int) (MAX( quad[1][0], quad[2][0] ) + 0.5F ) - cr.x;
605 cr.height = (int) (MAX( quad[2][1], quad[3][1] ) + 0.5F ) - cr.y;
608 xshift = maxshiftf * rand() / RAND_MAX;
609 yshift = maxshiftf * rand() / RAND_MAX;
611 cr.x -= (int) ( xshift * cr.width );
612 cr.y -= (int) ( yshift * cr.height );
613 cr.width = (int) ((1.0 + maxshiftf) * cr.width );
614 cr.height = (int) ((1.0 + maxshiftf) * cr.height);
616 randscale = maxscalef * rand() / RAND_MAX;
617 cr.x -= (int) ( 0.5 * randscale * cr.width );
618 cr.y -= (int) ( 0.5 * randscale * cr.height );
619 cr.width = (int) ((1.0 + randscale) * cr.width );
620 cr.height = (int) ((1.0 + randscale) * cr.height);
622 scale = MAX( ((float) cr.width) / bgimg->cols, ((float) cr.height) / bgimg->rows );
624 roi.x = (int) (-0.5F * (scale * bgimg->cols - cr.width) + cr.x);
625 roi.y = (int) (-0.5F * (scale * bgimg->rows - cr.height) + cr.y);
626 roi.width = (int) (scale * bgimg->cols);
627 roi.height = (int) (scale * bgimg->rows);
629 img = cvCreateImage( cvSize( bgimg->cols, bgimg->rows ), IPL_DEPTH_8U, 1 );
630 maskimg = cvCreateImage( cvSize( bgimg->cols, bgimg->rows ), IPL_DEPTH_8U, 1 );
632 cvSetImageROI( data->img, roi );
633 cvResize( data->img, img );
634 cvResetImageROI( data->img );
635 cvSetImageROI( data->maskimg, roi );
636 cvResize( data->maskimg, maskimg );
637 cvResetImageROI( data->maskimg );
639 forecolordev = (int) (maxintensitydev * (2.0 * rand() / RAND_MAX - 1.0));
641 for( r = 0; r < img->height; r++ )
643 for( c = 0; c < img->width; c++ )
645 pimg = (uchar*) img->imageData + r * img->widthStep + c;
646 pbg = (uchar*) bgimg->data.ptr + r * bgimg->step + c;
647 palpha = (uchar*) maskimg->imageData + r * maskimg->widthStep + c;
648 chartmp = (uchar) MAX( 0, MIN( 255, forecolordev + (*pimg) ) );
653 *pbg = (uchar) (( chartmp*(*palpha )+(255 - (*palpha) )*(*pbg) ) / 255);
657 cvReleaseImage( &img );
658 cvReleaseImage( &maskimg );
661 void icvEndSampleDistortion( CvSampleDistortionData* data )
665 cvReleaseImage( &data->src );
669 cvReleaseImage( &data->mask );
673 cvReleaseImage( &data->erode );
677 cvReleaseImage( &data->dilate );
681 cvReleaseImage( &data->img );
685 cvReleaseImage( &data->maskimg );
689 void icvWriteVecHeader( FILE* file, int count, int width, int height )
694 /* number of samples */
695 fwrite( &count, sizeof( count ), 1, file );
697 vecsize = width * height;
698 fwrite( &vecsize, sizeof( vecsize ), 1, file );
701 fwrite( &tmp, sizeof( tmp ), 1, file );
702 fwrite( &tmp, sizeof( tmp ), 1, file );
705 void icvWriteVecSample( FILE* file, CvArr* sample )
712 mat = cvGetMat( sample, &stub );
714 fwrite( &chartmp, sizeof( chartmp ), 1, file );
715 for( r = 0; r < mat->rows; r++ )
717 for( c = 0; c < mat->cols; c++ )
719 tmp = (short) (CV_MAT_ELEM( *mat, uchar, r, c ));
720 fwrite( &tmp, sizeof( tmp ), 1, file );
726 int cvCreateTrainingSamplesFromInfo( const char* infoname, const char* vecfilename,
729 int winwidth, int winheight )
731 char fullname[PATH_MAX];
741 int x, y, width, height;
744 assert( infoname != NULL );
745 assert( vecfilename != NULL );
748 if( !icvMkDir( vecfilename ) )
752 fprintf( stderr, "Unable to create directory hierarchy: %s\n", vecfilename );
753 #endif /* CV_VERBOSE */
758 info = fopen( infoname, "r" );
763 fprintf( stderr, "Unable to open file: %s\n", infoname );
764 #endif /* CV_VERBOSE */
769 vec = fopen( vecfilename, "wb" );
774 fprintf( stderr, "Unable to open file: %s\n", vecfilename );
775 #endif /* CV_VERBOSE */
782 sample = cvCreateImage( cvSize( winwidth, winheight ), IPL_DEPTH_8U, 1 );
784 icvWriteVecHeader( vec, num, sample->width, sample->height );
788 cvNamedWindow( "Sample", CV_WINDOW_AUTOSIZE );
791 strcpy( fullname, infoname );
792 filename = strrchr( fullname, '\\' );
793 if( filename == NULL )
795 filename = strrchr( fullname, '/' );
797 if( filename == NULL )
806 for( line = 1, error = 0, total = 0; total < num ;line++ )
810 error = ( fscanf( info, "%s %d", filename, &count ) != 2 );
813 src = cvLoadImage( fullname, 0 );
814 error = ( src == NULL );
819 fprintf( stderr, "Unable to open image: %s\n", fullname );
820 #endif /* CV_VERBOSE */
824 for( i = 0; (i < count) && (total < num); i++, total++ )
826 error = ( fscanf( info, "%d %d %d %d", &x, &y, &width, &height ) != 4 );
828 cvSetImageROI( src, cvRect( x, y, width, height ) );
829 cvResize( src, sample, width >= sample->width &&
830 height >= sample->height ? CV_INTER_AREA : CV_INTER_LINEAR );
834 cvShowImage( "Sample", sample );
835 if( cvWaitKey( 0 ) == 27 )
840 icvWriteVecSample( vec, sample );
845 cvReleaseImage( &src );
852 fprintf( stderr, "%s(%d) : parse error", infoname, line );
853 #endif /* CV_VERBOSE */
861 cvReleaseImage( &sample );
871 void cvShowVecSamples( const char* filename, int winwidth, int winheight,
880 file.input = fopen( filename, "rb" );
882 if( file.input != NULL )
884 size_t elements_read1 = fread( &file.count, sizeof( file.count ), 1, file.input );
885 size_t elements_read2 = fread( &file.vecsize, sizeof( file.vecsize ), 1, file.input );
886 size_t elements_read3 = fread( &tmp, sizeof( tmp ), 1, file.input );
887 size_t elements_read4 = fread( &tmp, sizeof( tmp ), 1, file.input );
888 CV_Assert(elements_read1 == 1 && elements_read2 == 1 && elements_read3 == 1 && elements_read4 == 1);
890 if( file.vecsize != winwidth * winheight )
895 fprintf( stderr, "Warning: specified sample width=%d and height=%d "
896 "does not correspond to .vec file vector size=%d.\n",
897 winwidth, winheight, file.vecsize );
898 if( file.vecsize > 0 )
900 guessed_w = cvFloor( sqrt( (float) file.vecsize ) );
903 guessed_h = file.vecsize / guessed_w;
907 if( guessed_w <= 0 || guessed_h <= 0 || guessed_w * guessed_h != file.vecsize)
909 fprintf( stderr, "Error: failed to guess sample width and height\n" );
910 fclose( file.input );
916 winwidth = guessed_w;
917 winheight = guessed_h;
918 fprintf( stderr, "Guessed width=%d, guessed height=%d\n",
919 winwidth, winheight );
923 if( !feof( file.input ) && scale > 0 )
925 CvMat* scaled_sample = 0;
928 file.vector = (short*) cvAlloc( sizeof( *file.vector ) * file.vecsize );
929 sample = scaled_sample = cvCreateMat( winheight, winwidth, CV_8UC1 );
932 scaled_sample = cvCreateMat( MAX( 1, cvCeil( scale * winheight ) ),
933 MAX( 1, cvCeil( scale * winwidth ) ),
936 cvNamedWindow( "Sample", CV_WINDOW_AUTOSIZE );
937 for( i = 0; i < file.count; i++ )
939 icvGetHaarTraininDataFromVecCallback( sample, &file );
940 if( scale != 1.0 ) cvResize( sample, scaled_sample, CV_INTER_LINEAR);
941 cvShowImage( "Sample", scaled_sample );
942 if( cvWaitKey( 0 ) == 27 ) break;
944 if( scaled_sample && scaled_sample != sample ) cvReleaseMat( &scaled_sample );
945 cvReleaseMat( &sample );
946 cvFree( &file.vector );
948 fclose( file.input );