OpenCV 2.4 & 3.0 Cheatsheet and Differences (C++)
In this post, we’ll talk about the most common OpenCV API’s and their usage. We call this list Cheatsheet because it comes very handy as a reference when you are working on any OpenCV project.
I personally, use it all the time, thus sharing it with everyone.
Let’s begin with the Key OpenCV Classes.
Point_ | Template 2D point class |
Point3_ | Template 3D point class |
Size_ | Template size (width, height) class |
Vec | Template short vector class |
Matx | Template small matrix class |
Scalar | 4-element vector |
Rect | Rectangle |
Range | Integer value range |
Mat | 2D or multi-dimensional dense array (can be used to store matrices, images, histograms, feature descriptors, voxel volumes etc.) |
SparseMat | Multi-dimensional sparse array |
Ptr | Template smart pointer class |
Now, let’s look at the Matrix Basics:-
- Matrix Basics Create a matrix
Mat image(240, 320, CV_8UC3);
- [Re]allocate a pre-declared matrix
image.create(480, 640, CV_8UC3);
- Create a matrix initialized with a constant
Mat A33(3, 3, CV_32F, Scalar(5));
Mat B33(3, 3, CV_32F);
B33 = Scalar(5);
Mat C33 = Mat::ones(3, 3, CV_32F)*5.;
Mat D33 = Mat::zeros(3, 3, CV_32F) + 5.;
- Create a matrix initialized with specified values
double a = CV_PI/3; Mat A22 = (Mat_(2, 2) « cos(a), -sin(a), sin(a), cos(a));
float B22data[] = {cos(a), -sin(a), sin(a), cos(a)};
Mat B22 = Mat(2, 2, CV_32F, B22data).clone();
- Initialize a random matrix
randu(image, Scalar(0), Scalar(256)); // uniform dist
randn(image, Scalar(128), Scalar(10)); // Gaussian dist
- Convert matrix to/from other structures (without copying the data)
Mat image_alias = image;
float* Idata=new float[480*640*3];
Mat I(480, 640, CV_32FC3, Idata);
vector iptvec(10); Mat iP(iptvec); // iP – 10×1 CV_32SC2 matrix
IplImage* oldC0 = cvCreateImage(cvSize(320,240),16,1);
Mat newC = cvarrToMat(oldC0);
IplImage oldC1 = newC;
CvMat oldC2 = newC; … (with copying the data)
Mat newC2 = cvarrToMat(oldC0).clone();
vector ptvec = Mat_(iP);
For more info, refer to attached file.
http://docs.opencv.org/3.0-last-rst/opencv_cheatsheet.pdf
Below is a short summary on what’s new in 3.0 vs 2.4:
- Many bug fixes and patches
- opencv_contrib (http://github.com/itseez/opencv_contrib) repository has been added. A lot of new functionality is there already! opencv_contrib is only compatible with 3.0/master, not 2.4.
- T-API (transparent API) has been introduced, this is transparent GPU acceleration layer using OpenCL. It does not add any compile-time or runtime dependency of OpenCL.
- ~40 OpenCV functions have been accelerated using NEON intrinsic
- Greatly improved and extended Python & Java bindings
- Improved Android support – now OpenCV Manager is in Java and supports both 2.4 and 3.0.
- Greatly improved WinRT support, including video capturing and multi-threading capabilities.
- GSoC projects have been integrated in opencv 3.0 and opencv_contrib. Some of them are :
- text detection
- many computational photography algorithms (HDR, inpainting, edge-aware filters, superpixels)
- tracking and optical flow algorithms
- new features, including line descriptors, KAZE/AKAZE
- general use optimization (hill climbing, linear programming)
- greatly improved Python support, including Python 3.0 support, many new tutorials & samples on how to use OpenCV with Python.
- 2d shape matching module and 3d surface matching module
- RGB-D module
- VTK-based 3D visualization module
etc.
- Other features include:
- biologically inspired vision module
- DAISY features, LATCH descriptor, improved BRIEF
- image registration module
etc.
Hope this helps you