Top 10 OpenCV Everyone Has To Know About

栏目: IT技术 · 发布时间: 6年前

内容简介: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)

Top 10 OpenCV Everyone Has To Know About

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

Top 10 OpenCV Everyone Has To Know About

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.

Top 10 OpenCV Everyone Has To Know About

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

  1. INTER_NEAREST: Nearest neighbor interpolation
  2. INTER_LINEAR: Bilinear interpolation
  3. INTER_CUBIC: Bicubic interpolation over 4×4 pixel neighborhood
  4. INTER_LANCZOS4: Lanczos interpolation over 8×8 neighborhood

Top 10 OpenCV Everyone Has To Know About

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)

Top 10 OpenCV Everyone Has To Know About

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])
Top 10 OpenCV Everyone Has To Know About

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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

冷启动

冷启动

高臻臻 / 人民邮电出版社 / 2018-5 / 59.80元

本书针对中小企业做营销没预算、没用户的痛点,系统梳理冷启动项目的思维和策略,帮助营销和运营人员实现项目从0到1再到n的爆发式增长。 全书有两条主线。一条是营销思维线,侧重于如何思考,包括:升级行业、创新文化,寻找营销切入点;挖掘品 牌和个人的亮点、“做轻”产品,打造具有互联网营销特色的冷启动项目;突破思维,把实体经济“做虚”,发挥虚拟经济的价值。另一条是营销策略线,侧重于如何行动,包......一起来看看 《冷启动》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

URL 编码/解码
URL 编码/解码

URL 编码/解码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器