Here is a description of some of the most fundamental and easy to use functions in openCV.
This should be a good starting point for beginners ….
Function CvLoadImage – Used to load an image data into an IplImage array
cvLoadImage(const char* fileName, int iscolor)
file name – Name of the image to load
iscolor - number of channels of the image
If iscolor > 0 the image loaded will always have 3 channels
If iscolor < 0 the image will be loaded with the number of channels based on the file
If iscolor = 0 the image will always have 1 channel.
Channel : A channel is the number of numbers used to specify a pixel value…
In RGB say each pixel’s color is specified by it’s R, G, B values. Hence, channels = 3.
IplImage *grayScaleImage;
//Create the image…
grayScaleImage = cvCreateImage(cvSize(320,240),8,1);
Function cvCreateImage – Used to create and allocate image data
cvCreateImage(CvSize size, int bitDepth, int channels);
CvSize is a OpenCV basic structure.
typedef struct CvSize
{
int width;
int height;
}
Size – size of the Image
bitDepth – the bitDepth of the image
Bit Depth: Bit Depth is the number of bits used to store information about an image.
Alternately for the bitDepth one can also use the OpenCV constants like IPL_DEPTH_8U, IPL_DEPTH_16S etc…
channels – Number of channels in the image
//Convert the original image to grayscale
cvCvtColor(originalImage, grayScaleImage, CV_BGR2GRAY);
Function cvCvtColor – Used to convert Images in one color space to another
cvCvtColor(const CvArr* SourceImage, const cvArr* DestinationImage, int code)
“code” – color conversion operation to be performed.
There are numerous conversion operations listed in OpenCV. They include conversion to and from RGB, YCrCb, HSV and Bayer.
CvArr is just a basic structure in OpenCV. It is used only in functions to specify that the parameter accepts more than one kind of array (there are many types of arrays in OpenCV and IplImage is one such type).
// Edge detection
IplImage * edgeImage; //Declare an image for holding the results of the edge detection perfomed on the grayScaleImage.
edgeImage = cvCreateImage(cvSize(320,240), 8, 1); //Create Image
//Perform edge detection using the canny edge detector
cvCanny(grayScaleImage, edgeImage, 0.5, 0.5, 3);
Function cvCanny – Used to perform edge detection with the Canny Operator
cvCanny(const cvArr *Image1, const cvArr *Image2, double threshold1, double threshold2, int kernel_size)
Image1 – Original Image on which edge detection is to be performed.
Image2 – The results of the edge detected image.
threshold1 and threshold2 – Thresholds for the canny detector.
kernel_size – Size of the sobel kernel – Value of 3 gives a 3 X 3 kernel.
//If all goes well we need to save the results of the edge detection.
cvSaveImage(“Resultant.jpg”,edgeImage);
Function cvSaveImage – Used to save an IplImage as a Image
cvSaveImage(const char* FileName, const CvArr* Image);
FileName – Name of the save file
Image – Image to be saved
//Finally release the memory for the images that were created
cvReleaseImage(&edgeImage);
cvReleaseImage(&grayScaleImage);
Function cvReleaseImage – Used to release the image data
cvReleaseImage(IplImage **Image)
Image – Image to be released


