Friday, September 5, 2014

Capture Video from File or Camera

Capture Video From File

In this lesson, I am going to show you how to read a video file. It's fairly simple. You just need to initialize a VideoCapture object which will open a video file and read frame by frame from that opened video. Here is the sample OpenCV code. If you are using Visual Studio, you will need to include "stdafx.h" header file.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap("C:/Users/SHERMAL/Desktop/SampleVideo.avi"); // open the video file for reading

    if ( !cap.isOpened() )  // if not success, exit program
    {
         cout << "Cannot open the video file" << endl;
         return -1;
    }

    //cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms

    double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

     cout << "Frame per seconds : " << fps << endl;

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

    while(1)
    {
        Mat frame;

        bool bSuccess = cap.read(frame); // read a new frame from video

if (!bSuccess) //if not success, break loop
{
                        cout << "Cannot read the frame from video file" << endl;
break;
}

        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
{
                cout << "esc key is pressed by user" << endl;
break; 
}
    }

    return 0;

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
You can download this OpenCV visual c++ project from here. (The downloaded file is a compressed .rar folder. So, you have to extract it using Winrar or other suitable software) 

This is how  I play a video using my OpenCV program


New OpenCV functions which are not found earlier are explained here
  • VideoCapture::VideoCapture(const string& filename)
This is one of few constructors available in VideoCapture class. This constructor open the video file and initializes the VideoCapture object for reading the video stream from the specified file. 
The destructor of this class will deallocated any associated memory with this object. Therefore you don't need to deallocate memory explicitly in your program.

  • bool VideoCapture::IsOpened()
If the previous call to VideoCapture constructor is successful, this method will return true. Otherwise it will return false. 
It is essential to check that whether the VideoCapture initialize successfully. If it is unsuccessful, program should be exited. Otherwise when you try to read a frame from the VideoCapture object, your program will crash.

  • bool VideoCapture::set(int propId, double value)
You can change some properties of VideoCapture object. If it is successful, this method will return true. Otherwise it will return false. You should try to change some properties of the video stream in your code. In my code, I have shown you how to change the position of the video, by changing the CV_CAP_PROP_POS_MSEC property.

Parameters :
  • int propID - This argument specify the property you are going to change. There are  many options for this argument. Some of them are listed here.  
    • CV_CAP_PROP_POS_MSEC - current position of the video in milliseconds
    • CV_CAP_PROP_POS_FRAMES - current position of the video in frames
    • CV_CAP_PROP_FRAME_WIDTH - width of the frame of the video stream
    • CV_CAP_PROP_FRAME_HEIGHT - height of the frame of the video stream
    • CV_CAP_PROP_FPS - frame rate (frames per second)
    • CV_CAP_PROP_FOURCC - four character code  of codec
  • double value - This is the new value you are going to assign to the property, specified by the propID

  • doubleVideoCapture::get(int propId)
This function returns the value of the property which is specified by propId. You should try to obtain some properties of the video stream in your code. In my code, I have shown you how to obtain the frame rate (frames per second) of the video, by using the CV_CAP_PROP_FPS argument.

Parameters - 
  • int propID - This argument specify the property you are going to obtain. There are many options for this argument. Some of them are listed here.  
    • CV_CAP_PROP_POS_MSEC - current position of the video in milliseconds
    • CV_CAP_PROP_POS_FRAMES - current position of the video in frames
    • CV_CAP_PROP_FRAME_WIDTH - width of the frame of the video stream
    • CV_CAP_PROP_FRAME_HEIGHT - height of the frame of the video stream
    • CV_CAP_PROP_FPS - frame rate (frames per second)
    • CV_CAP_PROP_FOURCC - four character code  of codec

  • bool VideoCapture::read(Mat& image);
The function grabs the next frame from the video, decodes it and stores it in the 'image' variable. Inside this function, VideoCapture::grap() and VideoCapture::retrieve() will be called. If you want, you can use these two functions instead of VideoCapture::read() function. 
If the operation successful, it will return true. Otherwise it will return false.

  • waitKey(30)
The function waits for 30 milliseconds. If a key was pressed before the specified time, it returns the ASCII value of the pressed key. If that value is 27 (ASCII value of 'esc' key is 27), the program will execute inside the if block. If no key is pressed during that 30ms, the function returns -1 program will continue the while loop.

  • VideoCapture::~VideoCapture()
Destructor of VideoCapture object will destroy any associated memory of that particular object. This destructor will be called implicitly on exit of the main method of the above program.


Summary

At first, this program captures a video from a file. Then the program enters into a infinite loop. In that loop, it grabs frames from the captured video sequentially, decodes it, shows it in a window and waits for 30 milliseconds. If the video file has no more frames or if the user presses the 'esc' key, the program will break the infinite loop.

Note:
Using waitKey(int) function is very important because imshow(string&, MAT) function need time to paint the image in the window and waitKey(int) will give that necessary time.



Capture Video From Camera


The main difference of the following program from the above program is the argument to the VideoCapture constructor. Here you just need to give the index of your camera to the constructor of the VideoCapture object instead of the filename in the above program. Here is the sample OpenCV code.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
    VideoCapture cap(0); // open the video camera no. 0

    if (!cap.isOpened())  // if not success, exit program
    {
cout << "Cannot open the video cam" << endl;
        return -1;
    }

   double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
   double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video

    cout << "Frame size : " << dWidth << " x " << dHeight << endl;

    namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"

    while (1)
    {
        Mat frame;

        bool bSuccess = cap.read(frame); // read a new frame from video

if (!bSuccess) //if not success, break loop
{
cout << "Cannot read a frame from video stream" << endl;
break;
}

        imshow("MyVideo", frame); //show the frame in "MyVideo" window

        if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
break; 
}
    }
    return 0;

}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

You can download this OpenCV visual c++ project from here. (The downloaded file is a compressed .rar folder. So, you have to extract it using Winrar or other suitable software)

This is how  I capture myself with my webcam using the OpenCV program



New OpenCV functions which are not found earlier are explained here
  • VideoCapture::VideoCapture(int device)
This is one of constructors available in VideoCapture class. This constructor open the camera indexed by  the argument of this constructor and initializes the VideoCapture object for reading the video stream from the specified camera.
Here the '0' means the index of the camera to be used. You can use 1,2,3.. instead of 0, if your computer is attached to more than 1 camera. 
The destructor of this class will deallocated any associated memory with this object. Therefore you don't need to deallocate memory explicitly in your program.

  • if (!cap.isOpened())
If the VideoCapture object initialization unsuccessful, the expression inside the 'if 'parentheses will evaluate to true and the statements inside the 'if' block will be executed. 
It is a good practice to check this scenario and handle it accordingly because otherwise it may cause the program to crash.


  • double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH)
This function obtain the width (in pixels) of frames of the camera output.

  •  double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT)
This function obtain the height (in pixels) of frames of the camera output.

 All other OpenCV functions and their arguments are exactly same as the 1st program.

Read & Display Image

Read Image from File and Display




Here I am going to explain how to read an image from a file and display the content using OpenCV library functions. First of all, open your C++ IDE and create a new project. You have to configure your new project  in order to use OpenCV library functions. If you have not configured the project for OpenCV yet, please refer to Installing & Configuring with Visual Studio.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, const char** argv )
{
  Mat img = imread("MyPic.JPG", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'

if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
          //system("pause"); //wait for a key press
return -1;
}

namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window

waitKey(0); //wait infinite time for a keypress

     destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"

return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Before you run this program, put any image file (MyPic.JPG) into the folder where your c++ file is.Otherwise you have to change the first argument of imread() function and give the absolute path to your image file.

You can download this OpenCV visual c++ project from here. (The downloaded file is a compressed .rar folder. So, you have to extract it using Winrar or other suitable software)


Load & Diplay Image from File
Load & Diplay Image from File

Explanation

Let's review the above OpenCV code line by line.
  • #include "stdafx.h"
If you are developing your application in Visual Studio, don't forget to put this line above the code.

  • #include "opencv2/highgui/highgui.hpp"
imread(), namedWindow(), imshow() and waitKey() functions are declared in the above header file. So you must include it.

We are using Mat data structure in the above program. It is declared in "opencv2/core/core.hpp" header file. Then why don't we include this? It's because "opencv2/highgui/highgui.hpp" header file include that header file inside it. So, we don't need to include it again in our program.

  • using namespace cv;
All the data structures and functions in "opencv2/core/core.hpp" and "opencv2/highgui/highgui.hpp" are declared inside cv namespace. So, we have to add the above line in the top of our program. Otherwise we have to append 'cv::' specifier before each OpenCV functions and data structures. (e.g - cv::Mat, cv::imread() , etc). If you are not familiar with namespaces, please refer this article. 

'#include <iostream>' and 'using namespace std' are added because we are using 'cout' to display some strings in the console. This is basic C++ and you should be familiar with this.

  • Mat img = imread(const string& filename, int flags=CV_LOAD_IMAGE_COLOR)
Mat is a data structure to store images in a matrix. It is declared in "opencv2/core/core.hpp" header file.

imread() is a function declared in "opencv2/highgui/highgui.hpp" header file. It loads an image from a file and stores it in Mat data structure.

Arguments of imread() function
  • filename - location of the file. If you just give the filename only, that image should be in the same folder as your C++ file. Otherwise you have to give the full path to your image.
  • flags - There are four possible inputs
    • CV_LOAD_IMAGE_UNCHANGED - image-depth=8 bits per pixel in each channel,  no. of channels=unchanged 
    • CV_LOAD_IMAGE_GRAYSCALE - image depth=8 bits,  no. of channels=1
    • CV_LOAD_IMAGE_COLOR - image-depth=?,  no. of channels=3
    • CV_LOAD_IMAGE_ANYDEPTH - image-depth=unchanged ,  no. of channels=?
    • CV_LOAD_IMAGE_ANYCOLOR - image-depth=?,  no. of channels=unchanged 

You can combine these above parameters to get desired image output.
e.g -
CV_LOAD_IMAGE_ANYDEPTH | CV_LOAD_IMAGE_ANYCOLOR - image-depth=unchanged,  no. of channels=unchanged 
CV_LOAD_IMAGE_COLOR | CV_LOAD_IMAGE_ANYDEPTH - image-depth=unchanged,  no. of channels=3

If you are not sure what to do, use CV_LOAD_IMAGE_COLOR as the 2nd parameter of imread() function.

To understand image-depth and concept of channels, you should be familiar with theory of image processing. So, let's discuss little bit of theory of image processing.

Any digital image consists of pixels. Any pixel should have some value. The minimum value for a pixel is 0 and it represents black.When the value of the pixel is increased, the intensity of that pixel is also increased.  In a computer memory, ). In decimal, it is 255. fixed number of bits are allocated for every pixel. Say the number of allocated bits per pixel is 8. Then the maximum number that a pixel can have is 255 (11111111 in binary)

Now what is image-depth? The image-depth means the number of bits allocated for each pixel. If it is 8, each pixel can have a value between 0 and 255. If it is 4, each pixel can have a value between 0 to 15 (1111 in binary). 

Here is a simple model of a image with image-depth of 8 bits. Each small box represents a pixel. So, each box may contain a value between 0 to 255.

Here is some properties of the following image.
  •  Image-depth 8 bit
  • 1 channel ( So, this is a grayscale image )
  • The height is 4 pixel 
  • The width is 5 pixels
  • The resolution of this image is 4x5.
This is a grayscale image (black and white image) because this image has no color content. If the value of this pixel is higher, it will be shown more brighter. If the value is low, it will be shown more darker.


Grayscale Image with image depth of 8
Grayscale Image with image depth of 8


Following image is a simple model of a color image. Color image should consist of at least 3 planes; Red, Green and Blue. Any color can be created using a particular combination of these 3 colors. Any pixel is a combination of three 3 values. (255, 0, 0) represent pure red. (0, 255, 0) represent pure green. (255, 0, 255) represents pure violate. In the same way, you can create many color. Image-depth is 24 because each pixel is represented with 8 x 3 bits (8 bits from each channel).

Here is some properties of the following image.
    •  Image-depth 24 bit
    • 3 channels ( So, this is a color image )
    • The height is 4 pixel 
    • The width is 5 pixels
    • The resolution of this image is 4x5.

Red, Green, Blue planes of a color image
R, G, B planes of a color image

In the above model, top left pixel is (23, 231, 46). It will be shown as a greenish color because the green value(231) of that pixel is larger than the red(23) and blue(46) value.

  • if (img.empty())
If imread() function fails to load the image, 'img' will not be loaded any data. Therefore 'img.empty()' should return true. It's a good practice to check whether the image is loaded successfully and if not exit the program. Otherwise your program will crash when executing imshow()function.

  • bool Mat::empty()
This function returns true, if Mat::data==NULL or Mat::total() == 0

  •  //system("pause");
If you are using Visual Studio, it's better to uncomment this line because it will pause the program until user press any key. If we don't uncomment it, the program will exit immediately so that user will not see the error message.
  • void namedWindow(const string& winname, int flags = WINDOW_AUTOSIZE);
This function creates a window.

Parameters -
  • winname - Title of the window. That name will display in the title bar of the newly created window
  • flags - determine the size of the window. There are two options
    • WINDOW_AUTOSIZE - User cannot resize the image. Image will be displayed in its original size
    • CV_WINDOW_NORMAL - Image will resized if you resize the the window

  • void imshow(const string& winname, InputArray mat);
This function shows the image which is stored in the 'mat' in a window specified by winname. If the window is created withWINDOW_AUTOSIZE flag, image will be displayed in its original size. Otherwise image may be scaled to the size of the window.

Parameters -
  • winname - Title of the window. This name is used to identify the window created by namedWindow() function.
  • mat - hold the image data

  • int waitKey(int delay = 0)
waitKey() function wait for keypress for certain time, specified by delay (in milliseconds). If delay is zero or negative, it will wait for infinite time. If any key is pressed, this function returns the ASCII value of the key and your program will continue. If there is no key press for the specified time, it will return -1 and program will continue.
  • void destroyWindow(const string& winname)
This function closes the opened window, with the title of winname and deallocate any associated memory usage. This function is not essential for this application because when the program exits, operating system usually close all the opened windows and deallocate any associated memory usage.


Summary

When running this program, the image of 'MyPic.JPG' is loaded into the variable, 'img' of type Mat. Then a window named 'MyWindow' is opened. After that  'img' is loaded to that window. The window with the image will be displayed until any key is pressed.



Create a Blank Image & Display

This program is also very much similar to the previous application. The only difference is that this program creates a blank image instead of loading an existing image from a file.

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, const char** argv )
{
  Mat img(500, 1000, CV_8UC3, Scalar(0,0, 100)); //create an image ( 3 channels, 8 bit image depth, 500 high, 1000 wide, (0, 0, 100) assigned for Blue, Green and Red plane respectively. )

if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
          //system("pause"); //wait for a key press
return -1;
}

namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window

waitKey(0);  //wait infinite time for a keypress

     destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"

return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Before you run this program, put any image file (MyPic.JPG) into the folder where your c++ file is.Otherwise you have to change the first argument of imread() function and give the absolute path to your image file.

You can download this OpenCV visual c++ project from here. (The downloaded file is a compressed .rar folder. So, you have to extract it using Winrar or other suitable software)

Create & Display Image
Create & Display Image
New OpenCV functions
  •  Mat::Mat(int rows, int cols, int type, const Scalar& s);
This is the one of the many constructor available in Mat class. It initialize the Mat object with the value given by the Scalar object

Parameters :
  • rows - Number of rows in the 2D array ( height of the image in pixels)
  • cols - Number of columns in the 2D array ( width of the image in pixels)
  • type - specify the bit depth, data type and number of channels of the image. I gave CV_8UC3 and it specify 8 bit unsigned integers with 3 channels. Here are some of possible inputs for this parameter
    • CV_8UC1 - 8 bit unsigned integers with single channel
    • CV_8UC3 - 8 bit unsigned integers with 3 channels
    • CV_64FC1 - 64 bit floating point value with 1 channels
If you want more details about this, please refer to Data Types for Arrays in the Basics of OpenCV API

  • s - Initialize each array element with the value given by s. In the above application, I gave Scalar(0,0,100). So, it initialize my first channel (Blue plane) with 0, 2nd channel (Green plane) with 0 and 3rd channel (Red Plane) with 100. So, my final image is red. You can try different combinations of these three and see the output image.
Summary
In this program, I created a 3 channel image with 500 height and 1000 width. 8 bit unsigned integer is allocated for each pixel in each channel. (8x3 = 24 bits per each pixel)  And each pixel is assigned with (0,0,100) scalar value. That means 1st channel is all zero, 2nd channel is also all zero and the 3rd channel is all 100. Therefore we can see a red image as the output of the program.

Basics of OpenCV API



Header files

These are some of important OpenCV header files for C++ interface. As a beginner, you will need few of these header files for your application. In my following lessons, I will include only necessary header files to my example programs. If you are not sure what to include, include them all. No any penalty incurred for including all this header file except for a fact that the length of your source code will increased by few lines than necessary.
    • #include "opencv2/core/core.hpp"
    • #include "opencv2/flann/miniflann.hpp"
    • #include "opencv2/imgproc/imgproc.hpp"
    • #include "opencv2/photo/photo.hpp"
    • #include "opencv2/video/video.hpp"
    • #include "opencv2/features2d/features2d.hpp"
    • #include "opencv2/objdetect/objdetect.hpp"
    • #include "opencv2/calib3d/calib3d.hpp"
    • #include "opencv2/ml/ml.hpp"
    • #include "opencv2/highgui/highgui.hpp"
    • #include "opencv2/contrib/contrib.hpp"
    • #include "opencv2/core/core_c.h"
    • #include "opencv2/highgui/highgui_c.h"
    • #include "opencv2/imgproc/imgproc_c.h"


Namespace 

All OpenCV classes and functions are in cv namespace. So, you have to do one of following
  • Add the 'using namespace cv' line just after including your header files (I have used this method in all my sample programs)
e.g.
                              #include "opencv2/core/core.hpp"
                              using namespace cv; 
                              int main()
                              {
                                         Mat frame = cvQueryFrame( capture );
                                         imshow( "Video", frame );
                              }



  • append the cv:: specifier at the beginning of every OpenCV classes, functions and data structures in your source code
e.g.                              
                              #include "opencv2/core/core.hpp"

                              int main()
                              {
                                         cv::Mat frame = cvQueryFrame( capture );
                                         cv::imshow( "Video", frame );
                              }


    Data Types for Arrays

    Data type of an array defines the number of bits allocated for each element of array (pixels in an image) and how the value is represented using those bits. Any array elements should have one of following data types.

    For single channel arrays : 

    • CV_8U (8 bit unsigned integer)
    • CV_8S (8 bit signed integer)
    • CV_16U (16 bit unsigned integer)
    • CV_16S (16 bit signed integer)
    • CV_32S (32 bit signed integer)
    • CV_32F (32 bit floating point number)
    • CV_64F (64 bit float floating point number)
    e.g. : Here I have illustrated a single channel array with 8 bit unsigned integers. As the datatype of this array is 8 bit unsigned integers, each element should have a value from 0 to 255.
    Single Channel Array with 8 bit unsigned integers
    Single Channel Array

    For multi channel arrays :

    We can define all of above data types for multi channel arrays (supports up to 512 channels). Here I am going to show you how to define CV_8U data type for multi channel arrays.
    • CV_8UC1 (single channel array with 8 bit unsigned integers) 
    • CV_8UC2 (2 channel array with 8 bit unsigned integers)
    • CV_8UC3 (3 channel array with 8 bit unsigned integers)
    • CV_8UC4 (4 channel array with 8 bit unsigned integers)
    • CV_8UC(n) (n channel array with 8 bit unsigned integers (n can be from 1 to 512) )
    e.g. 1 : Here I have illustrated a 3 channel array with 8 bit unsigned integers. As the datatype is 8 bit unsigned integers, each element should have a value from 0 to 255. Because this is a 3 channel array, array consists of tuples with 3 elements. The first tuple is {54, 0, 34}, second tuple is {58, 78, 185} and so on.
    3 - Channel Array for 8 bit unsigned integers
    3 Channel Arrays


    e.g. 2 : Here I have illustrated a 2 channel array with 8 bit signed integers. As the datatype is 8 bit signed integers, each element should have a value from -128 to 127. Because this is a 2 channel array, array consists of tuples with 2 elements. The first tuple is {-85, -127}, second tuple is {25, 23} and so on.
    2 Channel Array with 8 bit signed integers
    2 Channel Array
    Note : CV_8U = CV_8UC1 = CV_8UC(1)

    Example Usage :

    • Mat img1(3, 5, CV_32F ); //3 x 5 single-channel array with 32 bit floating point numbers
    • Mat img2(23, 53, CV_64FC(5) ); //23 x 53 5-channel array with 64 bit floating point numbers
    • Mat img3(Size(100, 200), CV_16UC2 ); //100 x 200 2-channel array with 16 bit unsigned integers
    Remember :
    Some OpenCV functions can handle only a subset of above data types. So, be careful, when using OpenCV functions. 


    Bit Depths for IplImage (C style)
    • IPL_DEPTH_<bit_depth>(S|U|F)
      • Here possible values for <bit_depth> are 1,8,16,32 and 64
      • S = Signed
      • U = Unsigned 
      • F = Float
      • 1 bit depth images should be unsigned
      • 8 bit depth images should be signed or unsigned
      • 16 bit depth images should be signed or unsigned
      • 32 bit depth images should be signed or float
      • 64 bit depth images should be float
    • E.g.:  
      • IPL_DEPTH_1U (1 bit depth and unsigned)
      • IPL_DEPTH_8U (8 bit depth and unsigned)
      • IPL_DEPTH_16U
      • IPL_DEPTH_32F ( 32 bit depth and float )
      • IPL_DEPTH_8S
      • IPL_DEPTH_16S ( 16 bit depth and signed )
      • IPL_DEPTH_32S
      • IPL_DEPTH_64F
    Bit depth means the number of bits allocated for a pixel. For example, IplImage with IPL_DEPTH_8U uses 8 bit unsigned integer per each pixel. That means each pixel can hold 0 to 255 integer numbers. 

    IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S,  IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are currently supported by IplImage data structure.

    What is OpenCV?


    OpenCV is an open source C++ library for image processing and computer vision, originally developed by Intel and now supported by Willow Garage. 
    It is free for both commercial and non-commercial use. Therefore it is not mandatory for your OpenCV applications to be open or free.
    It is a library of many inbuilt functions mainly aimed at real time image processing. Now it has several hundreds of image processing and computer vision algorithms which make developing advanced computer vision applications easy and efficient.
    If you are having any troubles with installing OpenCV or configure your Visual Studio IDE for OpenCV, please refer to Installing and Configuring with Visual Studio.

    Key Features
    • Optimized for real time image processing & computer vision applications
    • Primary interface of OpenCV is in C++
    • There are also C, Python and JAVA full interfaces
    • OpenCV applications run on Windows, Android, Linux, Mac and iOS
    • Optimized for Intel processors

    OpenCV Modules

    OpenCV has a modular structure. The main modules of OpenCV are listed below. I have provided some links which are pointing to some example lessons under each module.
    •  core                  
    This is the basic module of OpenCV. It includes basic data structures (e.g.- Mat data structure) and basic image processing functions. This module is also extensively used by other modules like highgui, etc.

    • highgui
    This module provides simple user interface capabilities, several image and video codecs, image and video capturing capabilities, manipulating image windows, handling track bars and mouse events  and etc. If you want more advanced UI capabilities, you have to use UI frameworks like Qt, WinForms, etc.
    e.g. - Load & Display Image, Capture Video from File or Camera, Write Image & Video to File

    • imgproc
    This module includes basic image processing algorithms including image filtering, image transformations, color space conversions and etc.

    •  video
    This is a video analysis module which includes object tracking algorithms, background subtraction algorithms and etc.
    • objdetect
    This includes object detection and recognition algorithms for standard objects. 


    OpenCV is now extensively used for developing advanced image processing and computer vision applications. It has been a tool for students, engineers and researchers in every nook and corner of the world.