内容简介:Before we go into the powerful functions of OpenCV, let’s take a look at the definitions of Computer Vision, Graphics, and OpenCV to understand better what we are doing here.Computer vision is an interdisciplinary field that deals with how computers can be
Before we go into the powerful functions of OpenCV, let’s take a look at the definitions of Computer Vision, Graphics, and OpenCV to understand better what we are doing here.
Computer Vision
Computer vision is an interdisciplinary field that deals with how computers can be made to gain a high-level understanding of digital images or videos. From the perspective of engineering, it seeks to automate tasks that the human visual system can do.
Computer Graphics
Computer graphics is a branch of computer science that deals with generating images with the aid of computers. Today, computer graphics is a core technology in digital photography, film, video games, cell phone and computer displays, and many specialized applications.
OpenCV
OpenCV (Open Source Computer Vision Library) is an open-source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in commercial products.
The library provides tools for processing and analyzing the content of images, including recognizing objects in digital photos (such as faces and figures of people, text, etc.), tracking the movement of objects, converting images, applying machine learning methods, and identifying common elements in various images.
Once we got that out of the way, we can begin with the top 10 Functions of my personal choice. (Code written with the functions is going to be in Python)
imread/imshow
This function has to be first since it is essential to starting your project with an image. As you can guess from the name of the function, it loads an image in the BGR (Blue-Green-Red) format.
import cv2 import matplotlib.pyplot as plotimage = cv2.imread('data.png') #load image plot.imshow(image) #show image
cvtColor
Once you load the image, you can also convert it to different color schemes using different flags in cvtColor.
cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
Here are some other flags for cvtColor: COLOR_BGR2GRAY, COLOR_BGR2HSV, and COLOR_BGR2YUV, etc.
This goes both ways, so COLOR_YUV2BGR, for example, is also possible.
resize
Sometimes you just need an image with a different size than the original so this is the function you need.
cv2.resize(image, dimension, interpolation = cv2.INTER_AREA)
It takes the original image and with dimension creates a new one. Dimension is defined as:
dimension = (width, height)
Interpolation is the way it resamples a picture, in my concrete example it uses INTER_AREA — resampling using pixel area relation and there are more of those like
- INTER_NEAREST: Nearest neighbor interpolation
- INTER_LINEAR: Bilinear interpolation
- INTER_CUBIC: Bicubic interpolation over 4×4 pixel neighborhood
- INTER_LANCZOS4: Lanczos interpolation over 8×8 neighborhood
split/merge
Each picture has 3 channels and if we want to split each of them into separate images, we can do that by using split functions.
(channel_b, channel_g, channel_r) = cv2.split(img)
If the image is in the BGR format, it will separate each channel into those three variables you define.
After you have already split the channels and you want to merge them back together, you use merge .
cv2.merge(
channel_b, channel_g, channel_r)
vconcat/hconcat
Use vconcat()
, hconcat()
to concatenate (combine) images vertically and horizontally. v
means vertical and h
means horizontal.
cv2.vconcat([image1, image2])
cv2.hconcat([image1, image2])
ones/zeros
If you want to fill an image (Mat) with ones or zeros for all three dimensions because Mat requires 3 layers/dimensions for a color image.
size = 200, 200, 3 m = np.zeros(size, dtype=np.uint8) n = np.ones(size, dtype=np.uint8)
As a bonus function, there is one thing I want to add here and that is transpose function.
transpose
If we have a defined matrix mat that we want to transpose, all we have to do is use this function on it:
import numpy as np mat = np.array([[1, 2, 3], [4, 5, 6]]) mat_transpose = mat.transpose() print(mat_tranpose)
We get the output:
[[1 4] [2 5] [3 6]] #original input [[1, 2, 3] [4, 5, 6]]
We are done!
Next steps
This is mostly for beginners, but next time we will take a look at more advanced features of OpenCV.
Until then, follow me for more! :sunglasses:
Thanks for reading!
以上所述就是小编给大家介绍的《Top 10 OpenCV Everyone Has To Know About》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Web Analytics 2.0
Avinash Kaushik / Sybex / 2009-10-26 / USD 39.99
The bestselling book Web Analytics: An Hour A Day was the first book in the analytics space to move beyond clickstream analysis. Web Analytics 2.0 will significantly evolve the approaches from the fir......一起来看看 《Web Analytics 2.0》 这本书的介绍吧!