OpenCV
Image Source:OpenCV
OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc.
In OpenCV, the CV is an abbreviation form of a computer vision, which is defined as a field of study that helps computers to understand the content of the digital images such as photographs and videos.
The purpose of computer vision is to understand the content of the images. It extracts the description from the pictures, which may be an object, a text description, and three-dimension model, and so on. For example, cars can be facilitated with computer vision, which will be able to identify and different objects around the road, such as traffic lights, pedestrians, traffic signs, and so on, and acts accordingly.
Image Source: Javatpoint
Computer vision allows the computer to perform the same kind of tasks as humans with the same efficiency. There are a two main task which are defined below:
Object Classification:- In the object classification, we train a model on a dataset of particular objects, and the model classifies new objects as belonging to one or more of your training categories.
Object Identification:- In the object identification, our model will identify a particular instance of an object - for example, parsing two faces in an image and tagging one as Virat Kohli and other one as Rohit Sharma.
Image Source: Javatpoint
History
OpenCV stands for Open Source Computer Vision Library, which is widely used for image recognition or identification. It was officially launched in 1999 by Intel. It was written in C/C++ in the early stage, but now it is commonly used in Python for the computer vision as well.
The first alpha version of OpenCV was released for the common use at the IEEE Conference on Computer Vision and Pattern Recognition in 2000, and between 2001 and 2005, five betas were released. The first 1.0 version was released in 2006.
The second version of the OpenCV was released in October 2009 with the significant changes. The second version contains a major change to the C++ interface, aiming at easier, more type-safe, pattern, and better implementations. Currently, the development is done by an independent Russian team and releases its newer version in every six months.
Why OpenCV is used for Computer Vision?
- OpenCV is available for free of cost.
- Since the OpenCV library is written in C/C++, so it is quit fast. Now it can be used with Python.
- It require less RAM to usage, it maybe of 60-70 MB.
- Computer Vision is portable as OpenCV and can run on any device that can run on C.
Features of OpenCV Library
Using OpenCV library, we can โ
- Read and write images
- Capture and save videos
- Process images (filter, transform)
- Perform feature detection
- Detect specific objects such as faces, eyes, cars, in the videos or images.
- Analyze the video, i.e., estimate the motion in it, subtract the background, and track objects in it.
OpenCV Library Modules
Following are the main library modules of the OpenCV library.
Core Functionality:- This module covers the basic data structures such as Scalar, Point, Range, etc., that are used to build OpenCV applications. In addition to these, it also includes the multidimensional array Mat, which is used to store the images. In the Java library of OpenCV, this module is included as a package with the name org.opencv.core.
Image Processing:- This module covers various image processing operations such as image filtering, geometrical image transformations, color space conversion, histograms, etc. In the Java library of OpenCV, this module is included as a package with the name org.opencv.imgproc.
Video:- This module covers the video analysis concepts such as motion estimation, background subtraction, and object tracking. In the Java library of OpenCV, this module is included as a package with the name org.opencv.video.
Video I/O:- This module explains the video capturing and video codecs using OpenCV library. In the Java library of OpenCV, this module is included as a package with the name org.opencv.videoio.
calib3d:- This module includes algorithms regarding basic multiple-view geometry algorithms, single and stereo camera calibration, object pose estimation, stereo correspondence and elements of 3D reconstruction. In the Java library of OpenCV, this module is included as a package with the name org.opencv.calib3d.
features2d:- This module includes the concepts of feature detection and description. In the Java library of OpenCV, this module is included as a package with the name org.opencv.features2d.
Objdetect:- This module includes the detection of objects and instances of the predefined classes such as faces, eyes, mugs, people, cars, etc. In the Java library of OpenCV, this module is included as a package with the name org.opencv.objdetect.
Highgui:- This is an easy-to-use interface with simple UI capabilities. In the Java library of OpenCV, the features of this module is included in two different packages namely, org.opencv.imgcodecs and org.opencv.videoio.
Installation
- For installing OpenCv on Windows, checkout this link.
- For installing OpenCv on MacOS, checkout this link.
- For installing OpenCv on Linux(Ubuntu), checkout this link.
Advantages of using OpenCV
Ease of use: OpenCV is easy and simple to learn
Availability of many tutorials: The fact that there are lots of tutorials available is a big plus as one can access many learning resources.
Compatibility with leading coding languages: OpenCV works with almost all the leading programming languages today, including Python, C++ and Java.
Free to use: Undoubtedly, a big plus is the fact that it is open source and hence free to use.
Example
Read Color Image
import cv2
#read image
img = cv2.imread('D:/image-1.png')
#print its shape
print('Image Dimensions :', img.shape)Output:-
Image Dimensions : (400, 640, 3)
Read Image as Grey Scale
import cv2
img = cv2.imread('D:/image-1.png', cv2.IMREAD_GRAYSCALE)
print('Image Dimensions :', img.shape)Output:-
Image Dimensions : (400, 640)
Read Image with Transparency Channel
import cv2
img = cv2.imread('D:/image-1.png', cv2.IMREAD_UNCHANGED)
print('Image Dimensions :', img.shape)Output:-
Image Dimensions : (400, 640, 4)
Blur Image
import cv2
#read image
img_src = cv2.imread('sample.png')
#blur the image
img_rst = cv2.blur(img_src, (5, 5)
#save result image
cv2.imwrite('result.jpg',img_rst)Output:-
Image Source: [Python Examples](https://pythonexamples.org/wp-content/uploads/2020/03/opencv_cv2_blur.png)
Write Text on Image
import numpy as np
import cv2
image = cv2.imread('sample.png',cv2.IMREAD_UNCHANGED)
position = (10,50)
cv2.putText(
image, #numpy array on which text is written
"Python Examples", #text
position, #position at which writing has to start
cv2.FONT_HERSHEY_SIMPLEX, #font family
1, #font size
(209, 80, 0, 255), #font color
3) #font stroke
cv2.imwrite('output.png', image)Output:-
Input Image: sample.png
Output Image: output.png
OpenCV is truly a wonderful and powerpack library for computer vision tasks. OpenCV is not only used by prominent research centres like Stanford, MIT, CMU, Cambridge, and INRIA but also by tech giants like Google, Yahoo, Microsoft, Intel, Sony, Honda, Toyota, among others. Since its alpha release in January 1999, OpenCV has been used in many applications, products, and research efforts. One of the main motives behind the OpenCV library is to provide the researchers with a simple-to-use computer vision infrastructure that helps in building sophisticated vision applications quickly and efficiently.
REFERENCES:-