opencv计算机视觉
什么是计算机视觉? (What is Computer Vision?)
Computer Vision is like imparting human intelligence and instincts to acomputer. In other words it is a field of computer science that works onenabling computers to see, identify and process images in the same waythat the human eye does.Let us say you and your family went on a vacation and you uploaded a fewpictures on Facebook. However, it takes time to find your parents’ facesand tag them in each picture, Facebook is intelligent enough to tag peoplefor you.But, how do you think this auto-tag feature works? It works throughcomputer vision.
计算机视觉就像赋予计算机以人类智慧和本能。 换句话说,这是计算机科学领域,它使计算机能够以与人眼相同的方式查看,识别和处理图像。让我们说您和您的家人去度假了,您在Facebook上上传了一些图片。 但是,查找父母的脸并在每张照片中标记它们需要花费时间,Facebook足够智能为您标记人物,但是您如何看待这种自动标记功能呢? 它通过计算机视觉起作用。
什么是OpenCV? (What is OpenCV?)
OpenCV was built to provide a common infrastructure for computer visionapplications and to accelerate the use of machine perception in commercialproducts. This library has more than 2500 algorithms used to detect andrecognize human faces, identify images, track moving objects, extract 3Dmodels of objects.
OpenCV构建旨在为计算机视觉应用程序提供通用的基础结构,并加速在商业产品中使用机器感知。 该库具有2500多种算法,可用于检测和识别人脸,识别图像,跟踪运动对象,提取对象的3D模型。
安装OpenCV (Installation of OpenCV)
To install OpenCV for python use the following code in terminal:
要在python中安装OpenCV,请在终端中使用以下代码:
$ python3 -m pip install opencv-python$ python3 -m pip install opencv-contrib-python
$ python3 -m pip安装opencv-python $ python3 -m pip安装opencv-contrib-python
计算机如何读取图像? (How does a computer read an image?)
![Image for post](https://miro.medium.com/max/9999/1*5PpEQlQs9LrO6ajxXzbRTg.jpeg)
We can look at this image and figure it out that it belongs to New YorkSquare. But, computers cannot analyze it. It doesn’t have any intelligence.For any color image, there are 3 primary channels — red, green and blue.A matrix is formed for every primary color, and later, these matricescombine to provide a pixel value for the individual R, G, and B colors. Eachelement of the matrices provides data pertaining to the intensity of brightness of the pixel. It reads any image as a range of values between 0and 255.
我们可以查看一下这张图,并弄清楚它属于New YorkSquare。 但是,计算机无法对其进行分析。 它没有任何智能。对于任何彩色图像,都有3个原色通道-红色,绿色和蓝色。每种原色均形成一个矩阵,然后,这些矩阵组合起来为各个R,G提供像素值和B颜色。 矩阵的每个元素提供与像素的亮度强度有关的数据。 它读取任何图像作为0到255之间的值范围。
如何通过相机捕获图像和视频? (How to capture images and videos through a camera?)
import cv2
导入cv2
cap = cv2.VideoCapture(0)
上限= cv2.VideoCapture(0)
while True:
而True:
ret, frame = cap.read()
ret,frame = cap.read()
cv2.imshow(“Capturing”,frame)
cv2.imshow(“捕获”,