1 // The short example shows how to use new-style image classes declared in cxcore.hpp.
2 // There is also a very similar matrix class (CvMatrix) - a wrapper for CvMat
6 int main( int argc, char** argv )
8 // load image in constructor: the image can be loaded either from bitmap (see cvLoadImage),
9 // or from XML/YAML (see cvLoad)
10 CvImage img(argc > 1 ? argv[1] : "lena.jpg", 0, CV_LOAD_IMAGE_COLOR),
12 CvRNG rng = cvRNG(-1);
14 if( !img.data() ) // check if the image has been loaded properly
17 img_yuv = img.clone(); // clone the image
18 // (although, later the content will be replaced with cvCvtColor,
19 // clone() is used for simplicity and for the illustration)
20 cvCvtColor( img, img_yuv, CV_BGR2YCrCb ); // simply call OpenCV functions and pass the class instances there
22 y.create( img.size(), IPL_DEPTH_8U, 1 ); // another method to create an image - from scratch
23 noise.create( img.size(), IPL_DEPTH_32F, 1 );
25 cvSplit( img_yuv, y, 0, 0, 0 );
26 cvRandArr( &rng, noise, CV_RAND_NORMAL, cvScalarAll(0), cvScalarAll(20) );
27 cvSmooth( noise, noise, CV_GAUSSIAN, 5, 5, 1, 1 );
29 cvConvert( noise, y );
30 cvMerge( y, 0, 0, 0, img_yuv );
31 cvCvtColor( img_yuv, img, CV_YCrCb2BGR );
33 cvNamedWindow( "image with grain", CV_WINDOW_AUTOSIZE );
34 img.show( "image with grain" ); // .show method is the conveninient form of cvShowImage
38 // all the images will be released automatically