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.
46 class CV_EXPORTS CvImage
49 CvImage() : image(0), refcount(0) {}
50 CvImage( CvSize size, int depth, int channels )
52 image = cvCreateImage( size, depth, channels );
53 refcount = image ? new int(1) : 0;
56 CvImage( IplImage* img ) : image(img)
58 refcount = image ? new int(1) : 0;
61 CvImage( const CvImage& img ) : image(img.image), refcount(img.refcount)
63 if( refcount ) ++(*refcount);
66 CvImage( const char* filename, const char* imgname=0, int color=-1 ) : image(0), refcount(0)
67 { load( filename, imgname, color ); }
69 CvImage( CvFileStorage* fs, const char* mapname, const char* imgname ) : image(0), refcount(0)
70 { read( fs, mapname, imgname ); }
72 CvImage( CvFileStorage* fs, const char* seqname, int idx ) : image(0), refcount(0)
73 { read( fs, seqname, idx ); }
77 if( refcount && !(--*refcount) )
79 cvReleaseImage( &image );
84 CvImage clone() { return CvImage(image ? cvCloneImage(image) : 0); }
86 void create( CvSize size, int depth, int channels )
88 attach( cvCreateImage( size, depth, channels ));
91 void release() { detach(); }
92 void clear() { detach(); }
94 void attach( IplImage* img, bool use_refcount=true )
98 if( --*refcount == 0 )
99 cvReleaseImage( &image );
103 refcount = use_refcount && image ? new int(1) : 0;
110 if( --*refcount == 0 )
111 cvReleaseImage( &image );
118 bool load( const char* filename, const char* imgname=0, int color=-1 );
119 bool read( CvFileStorage* fs, const char* mapname, const char* imgname );
120 bool read( CvFileStorage* fs, const char* seqname, int idx );
121 void save( const char* filename, const char* imgname );
122 void write( CvFileStorage* fs, const char* imgname );
124 void show( const char* window_name );
125 bool is_valid() { return image != 0; }
127 int width() const { return image ? image->width : 0; }
128 int height() const { return image ? image->height : 0; }
130 CvSize size() const { return image ? cvSize(image->width, image->height) : cvSize(0,0); }
132 CvSize roi_size() const
134 return !image ? cvSize(0,0) :
135 !image->roi ? cvSize(image->width,image->height) :
136 cvSize(image->roi->width, image->roi->height);
141 return !image ? cvRect(0,0,0,0) :
142 !image->roi ? cvRect(0,0,image->width,image->height) :
143 cvRect(image->roi->xOffset,image->roi->yOffset,
144 image->roi->width,image->roi->height);
147 int coi() const { return !image || !image->roi ? 0 : image->roi->coi; }
149 void set_roi(CvRect roi) { cvSetImageROI(image,roi); }
150 void reset_roi() { cvResetImageROI(image); }
151 void set_coi(int coi) { cvSetImageCOI(image,coi); }
152 int depth() const { return image ? image->depth : 0; }
153 int channels() const { return image ? image->nChannels : 0; }
154 int pix_size() const { return image ? ((image->depth & 255)>>3)*image->nChannels : 0; }
156 uchar* data() { return image ? (uchar*)image->imageData : 0; }
157 const uchar* data() const { return image ? (const uchar*)image->imageData : 0; }
158 int step() const { return image ? image->widthStep : 0; }
159 int origin() const { return image ? image->origin : 0; }
161 uchar* roi_row(int y)
166 y<image->roi->height : y<image->height);
170 (uchar*)(image->imageData + y*image->widthStep) :
171 (uchar*)(image->imageData + (y+image->roi->yOffset)*image->widthStep +
172 image->roi->xOffset*((image->depth & 255)>>3)*image->nChannels);
175 const uchar* roi_row(int y) const
180 y<image->roi->height : y<image->height);
184 (const uchar*)(image->imageData + y*image->widthStep) :
185 (const uchar*)(image->imageData + (y+image->roi->yOffset)*image->widthStep +
186 image->roi->xOffset*((image->depth & 255)>>3)*image->nChannels);
189 operator const IplImage* () const { return image; }
190 operator IplImage* () { return image; }
192 CvImage& operator = (const CvImage& img)
196 if( refcount && !(--*refcount) )
197 cvReleaseImage( &image );
199 refcount=img.refcount;
209 class CV_EXPORTS CvMatrix
212 CvMatrix() : matrix(0) {}
213 CvMatrix( int rows, int cols, int type )
214 { matrix = cvCreateMat( rows, cols, type ); }
216 CvMatrix( int rows, int cols, int type, CvMat* hdr,
217 void* data=0, int step=CV_AUTOSTEP )
218 { matrix = cvInitMatHeader( hdr, rows, cols, type, data, step ); }
220 CvMatrix( int rows, int cols, int type, CvMemStorage* storage, bool alloc_data=true );
222 CvMatrix( int rows, int cols, int type, void* data, int step=CV_AUTOSTEP )
223 { matrix = cvCreateMatHeader( rows, cols, type );
224 cvSetData( matrix, data, step ); }
229 CvMatrix( const CvMatrix& m )
235 CvMatrix( const char* filename, const char* matname=0, int color=-1 ) : matrix(0)
236 { load( filename, matname, color ); }
238 CvMatrix( CvFileStorage* fs, const char* mapname, const char* matname ) : matrix(0)
239 { read( fs, mapname, matname ); }
241 CvMatrix( CvFileStorage* fs, const char* seqname, int idx ) : matrix(0)
242 { read( fs, seqname, idx ); }
249 CvMatrix clone() { return CvMatrix(matrix ? cvCloneMat(matrix) : 0); }
251 void set( CvMat* m, bool add_ref )
259 void create( int rows, int cols, int type )
261 set( cvCreateMat( rows, cols, type ), false );
268 if( matrix->hdr_refcount )
269 ++matrix->hdr_refcount;
270 else if( matrix->refcount )
279 if( matrix->hdr_refcount )
281 if( --matrix->hdr_refcount == 0 )
282 cvReleaseMat( &matrix );
284 else if( matrix->refcount )
286 if( --*matrix->refcount == 0 )
287 cvFree( &matrix->refcount );
298 bool load( const char* filename, const char* matname=0, int color=-1 );
299 bool read( CvFileStorage* fs, const char* mapname, const char* matname );
300 bool read( CvFileStorage* fs, const char* seqname, int idx );
301 void save( const char* filename, const char* matname );
302 void write( CvFileStorage* fs, const char* matname );
304 void show( const char* window_name );
306 bool is_valid() { return matrix != 0; }
308 int rows() const { return matrix ? matrix->rows : 0; }
309 int cols() const { return matrix ? matrix->cols : 0; }
313 return !matrix ? cvSize(0,0) : cvSize(matrix->rows,matrix->cols);
316 int type() const { return matrix ? CV_MAT_TYPE(matrix->type) : 0; }
317 int depth() const { return matrix ? CV_MAT_DEPTH(matrix->type) : 0; }
318 int channels() const { return matrix ? CV_MAT_CN(matrix->type) : 0; }
319 int pix_size() const { return matrix ? CV_ELEM_SIZE(matrix->type) : 0; }
321 uchar* data() { return matrix ? matrix->data.ptr : 0; }
322 const uchar* data() const { return matrix ? matrix->data.ptr : 0; }
323 int step() const { return matrix ? matrix->step : 0; }
325 void set_data( void* data, int step=CV_AUTOSTEP )
326 { cvSetData( matrix, data, step ); }
328 uchar* row(int i) { return !matrix ? 0 : matrix->data.ptr + i*matrix->step; }
329 const uchar* row(int i) const
330 { return !matrix ? 0 : matrix->data.ptr + i*matrix->step; }
332 operator const CvMat* () const { return matrix; }
333 operator CvMat* () { return matrix; }
335 CvMatrix& operator = (const CvMatrix& _m)
348 typedef IplImage* (CV_CDECL * CvLoadImageFunc)( const char* filename, int colorness );
349 typedef CvMat* (CV_CDECL * CvLoadImageMFunc)( const char* filename, int colorness );
350 typedef int (CV_CDECL * CvSaveImageFunc)( const char* filename, const CvArr* image );
351 typedef void (CV_CDECL * CvShowImageFunc)( const char* windowname, const CvArr* image );
353 CVAPI(int) cvSetImageIOFunctions( CvLoadImageFunc _load_image, CvLoadImageMFunc _load_image_m,
354 CvSaveImageFunc _save_image, CvShowImageFunc _show_image );
356 #define CV_SET_IMAGE_IO_FUNCTIONS() \
357 cvSetImageIOFunctions( cvLoadImage, cvLoadImageM, cvSaveImage, cvShowImage )
359 // classes for automatic module/RTTI data registration/unregistration
360 struct CV_EXPORTS CvModule
362 CvModule( CvModuleInfo* _info );
366 static CvModuleInfo* first;
367 static CvModuleInfo* last;
370 struct CV_EXPORTS CvType
372 CvType( const char* type_name,
373 CvIsInstanceFunc is_instance, CvReleaseFunc release=0,
374 CvReadFunc read=0, CvWriteFunc write=0, CvCloneFunc clone=0 );
378 static CvTypeInfo* first;
379 static CvTypeInfo* last;
382 #endif /*_CXCORE_HPP_*/