This is a basic example for the OpenCV.
First we must know the structure of IplImage:
IplImage |-- int nChannels; // Number of color channels (1,2,3,4) |-- int depth; // Pixel depth in bits: | // IPL_DEPTH_8U, IPL_DEPTH_8S, | // IPL_DEPTH_16U,IPL_DEPTH_16S, | // IPL_DEPTH_32S,IPL_DEPTH_32F, | // IPL_DEPTH_64F |-- int width; // image width in pixels |-- int height; // image height in pixels |-- char* imageData; // pointer to aligned image data | // Note that color images are stored in BGR order |-- int dataOrder; // 0 - interleaved color channels, | // 1 - separate color channels | // cvCreateImage can only create interleaved images |-- int origin; // 0 - top-left origin, | // 1 - bottom-left origin (Windows bitmaps style) |-- int widthStep; // size of aligned image row in bytes |-- int imageSize; // image data size in bytes = height*widthStep |-- struct _IplROI *roi;// image ROI. when not NULL specifies image | // region to be processed. |-- char *imageDataOrigin; // pointer to the unaligned origin of image data | // (needed for correct image deallocation) | |-- int align; // Alignment of image rows: 4 or 8 byte alignment | // OpenCV ignores this and uses widthStep instead |-- char colorModel[4]; // Color model - ignored by OpenCV //------------------------------------------------------------------------------