1. what is computer vision?
computer vision (Computer Vision, 简称CV) is artificial intelligence 一个branch, 它使计算机able tounderstanding and 解释graph像 and 视频in in 容. computer vision 目标 is 让计算机able to像人class一样"看懂"graph像 and 视频.
提示
computer vision涉及graph像processing, 模式识别, 机器Learningetc. many 个领域, is artificial intelligencein最活跃 研究方向之一.
1.1 computer vision challenges
- graph像 many 样性: 同一物体 in 不同光照, 角度, 背景 under 表现diff很 big .
- 计算complexity: processing high 分辨率graph像需要 big 量 计算resource.
- 语义understanding: 不仅要识别物体, 还要understanding物体之间 relationships and 场景 语义.
- 实时性要求: 许 many application (such as自动驾驶) 需要实时processinggraph像.
- data标注: 需要 big 量标注data来训练model.
2. computer vision basictask
2.1 graph像classification
graph像classification is computer vision Basicstask, 它 目标 is 将graph像classification to 预定义 class别in.
- 二classification: 将graph像分 for 两个class别 (such as猫 vs 狗) .
- many classification: 将graph像分 for many 个class别 (such asImageNet 1000个class别) .
- many tagclassification: 一个graph像可能属于 many 个class别.
2.2 目标检测
目标检测不仅要识别graph像in 物体class别, 还要定位物体 位置.
- edge界框检测: 用矩形框标记物体 位置.
- instance分割: 精确分割出每个物体 像素.
- 关键点检测: 检测物体 关键点 (such as人脸 关键点) .
2.3 graph像分割
graph像分割 is 将graph像分割成不同 区域 or 像素组.
- 语义分割: 将每个像素classification to 语义class别.
- instance分割: 区分同一class别 不同instance.
- 全景分割: 结合语义分割 and instance分割.
2.4 人脸识别
人脸识别 is 识别graph像 or 视频in 人脸并for身份确认.
- 人脸检测: 检测graph像in 人脸位置.
- 人脸特征提取: 提取人脸 特征向量.
- 人脸比 for : 比较两个人脸 相似度.
- 人脸verification: verification is 否 for specific 人.
- 人脸识别: 识别出人脸 for 应 身份.
2.5 物体跟踪
物体跟踪 is in 视频序列in跟踪specific物体 运动.
- 单目标跟踪: 跟踪视频in 单个目标.
- many 目标跟踪: 同时跟踪视频in many 个目标.
- 视觉跟踪: 基于视觉information 跟踪.
- many 模态跟踪: 结合other传感器information 跟踪.
2.6 graph像生成
graph像生成 is creation new graph像.
- graph像超分辨率: improvinggraph像 分辨率.
- graph像修复: 修复损 bad graph像.
- 风格migration: 将一幅graph像 风格application to 另一幅graph像.
- 文本 to graph像生成: 根据文本describes生成graph像.
2.7 3D重建
3D重建 is from 2Dgraph像 or 视频inrestore3Dstructure.
- 单目3D重建: from 单张graph像重建3Dstructure.
- many 目3D重建: from many 张不同视角 graph像重建3Dstructure.
- 视频3D重建: from 视频序列重建3Dstructure.
3. computer vision coretechniques
3.1 graph像processingBasics
graph像processing is computer vision Basics, including:
- graph像滤波: such as high 斯滤波, in值滤波etc..
- edge缘检测: such asSobel, Cannyetc.algorithms.
- graph像变换: such as傅里叶变换, 霍夫变换etc..
- graph像增强: such as直方graph均衡化, for 比度增强etc..
3.2 传statistics算机视觉algorithms
in 深度Learning兴起之 before , 传统 computer visionalgorithms主要including:
- 特征提取: such asSIFT, SURF, HOGetc..
- 目标检测: such asHaar cascades, HOG + SVMetc..
- graph像分割: such as阈值分割, 区域生 long , 分水岭algorithmsetc..
- 立体视觉: such as双目立体匹配algorithms.
3.3 深度Learning in computer visionin application
深度Learning 兴起极 big 地推动了computer vision 发展:
3.3.1 卷积神经network (CNN)
- LeNet: 最早 CNN之一, 用于手写number识别.
- AlexNet: 2012年ImageNet竞赛冠军, 深度Learning开始崛起.
- VGGNet: using更深 networkstructure.
- GoogLeNet/Inception: usingInceptionmodule.
- ResNet: using残差连接解决深层network 梯度消失issues.
- EfficientNet: using复合缩放method平衡network 深度, 宽度 and 分辨率.
3.3.2 目标检测model
- R-CNN系列: includingR-CNN, Fast R-CNN, Faster R-CNNetc..
- YOLO系列: 实时目标检测model.
- SSD: 单次 many 框检测器.
- RetinaNet: usingFocal Loss解决class别不平衡issues.
3.3.3 graph像分割model
- Fully Convolutional Networks (FCN): 全卷积network.
- U-Net: 用于医学graph像分割.
- Mask R-CNN: 结合目标检测 and instance分割.
- DeepLab系列: using空洞卷积 and many 尺度特征.
3.4 注意力mechanism
注意力mechanism in computer visionin application:
- Spatial Attention: 关注graph像 specific区域.
- Channel Attention: 关注specific 特征通道.
- Self-Attention: such asVision Transformerinusing 自注意力mechanism.
3.5 migrationLearning
migrationLearning in computer visionin非常 important :
- 预训练model: in big 型data集 (such asImageNet) on 预训练model.
- 微调: in specifictask on 微调预训练model.
- 特征提取: using预训练modelserving as特征提取器.
4. computer vision tool and library
4.1 graph像processinglibrary
4.1.1 OpenCV
- open-source computer visionlibrary.
- support many 种programminglanguage (C++, Python, Javaetc.) .
- package含 big 量传statistics算机视觉algorithms.
- performanceoptimization, 适合实时application.
4.1.2 PIL/Pillow
- Pythongraph像processinglibrary.
- providingbasic graph像processingfunctions.
- 易于using, 适合 simple graph像processingtask.
4.2 深度Learningframework
- TensorFlow: GoogleDevelopment 深度Learningframework.
- PyTorch: FacebookDevelopment 深度Learningframework.
- Keras: advanced神经networkAPI.
4.3 预训练modellibrary
- TorchVision: PyTorch computer visionlibrary, package含预训练model.
- TensorFlow Hub: TensorFlow modellibrary.
- ONNX Model Zoo: 开放神经network交换格式 modellibrary.
5. codeexample: usingOpenCVforgraph像processing
under 面 is a usingOpenCVforbasicgraph像processing example:
import cv2
import numpy as np
import matplotlib.pyplot as plt
# 读取graph像
img = cv2.imread('lena.jpg')
# 转换 for RGB格式 (OpenCV默认usingBGR)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 显示原始graph像
plt.figure(figsize=(15, 10))
plt.subplot(2, 3, 1)
plt.imshow(img_rgb)
plt.title('原始graph像')
plt.axis('off')
# 转换 for 灰度graph像
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
plt.subplot(2, 3, 2)
plt.imshow(img_gray, cmap='gray')
plt.title('灰度graph像')
plt.axis('off')
# edge缘检测
edges = cv2.Canny(img_gray, 100, 200)
plt.subplot(2, 3, 3)
plt.imshow(edges, cmap='gray')
plt.title('edge缘检测')
plt.axis('off')
# graph像模糊
blurred = cv2.GaussianBlur(img, (15, 15), 0)
blurred_rgb = cv2.cvtColor(blurred, cv2.COLOR_BGR2RGB)
plt.subplot(2, 3, 4)
plt.imshow(blurred_rgb)
plt.title(' high 斯模糊')
plt.axis('off')
# graph像阈值化
ret, thresh = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY)
plt.subplot(2, 3, 5)
plt.imshow(thresh, cmap='gray')
plt.title('阈值化')
plt.axis('off')
# graph像旋转
rows, cols = img.shape[:2]
M = cv2.getRotationMatrix2D((cols/2, rows/2), 45, 1)
rotated = cv2.warpAffine(img, M, (cols, rows))
rotated_rgb = cv2.cvtColor(rotated, cv2.COLOR_BGR2RGB)
plt.subplot(2, 3, 6)
plt.imshow(rotated_rgb)
plt.title('旋转45度')
plt.axis('off')
plt.tight_layout()
plt.show()
6. 实践case: usingPyTorchforgraph像classification
under 面 is a usingPyTorch and 预训练modelforgraph像classification example:
6.1 installation依赖
pip install torch torchvision opencv-python matplotlib
6.2 codeimplementation
import torch
import torchvision
from torchvision import transforms
import cv2
import matplotlib.pyplot as plt
# 加载预训练model
model = torchvision.models.resnet18(pretrained=True)
model.eval() # 设置 for assessment模式
# 加载ImageNetclass别tag
with open('imagenet_classes.txt', 'r') as f:
classes = [line.strip() for line in f.readlines()]
# graph像预processing
preprocess = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
# 读取 and 预processinggraph像
def classify_image(image_path):
# 读取graph像
img = cv2.imread(image_path)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# 转换 for PILgraph像
from PIL import Image
img_pil = Image.fromarray(img_rgb)
# 预processing
input_tensor = preprocess(img_pil)
input_batch = input_tensor.unsqueeze(0) # 添加批次维度
# usingGPU (such as果可用)
if torch.cuda.is_available():
input_batch = input_batch.to('cuda')
model.to('cuda')
# 预测
with torch.no_grad():
output = model(input_batch)
# 获取预测结果
probabilities = torch.nn.functional.softmax(output[0], dim=0)
top_prob, top_catid = torch.topk(probabilities, 5)
# 显示结果
plt.figure(figsize=(10, 6))
plt.imshow(img_rgb)
plt.title('graph像classification结果')
plt.axis('off')
# 显示顶部预测
print('预测结果:')
for i in range(top_prob.size(0)):
print(f'{i+1}. {classes[top_catid[i]]}: {top_prob[i].item():.4f}')
plt.show()
# testgraph像classification
classify_image('cat.jpg')
7. computer vision application场景
7.1 自动驾驶
- 车道线检测.
- 车辆检测 and 跟踪.
- 行人检测.
- 交通信号识别.
- environment感知 and pathplanning.
7.2 人脸识别
- 身份verification and 识别.
- 安防monitor.
- 人脸支付.
- 表情analysis.
- 门禁system.
7.3 医疗影像analysis
- disease diagnosis (such as肿瘤检测) .
- 医学影像分割.
- 手术导航.
- 医学影像增强.
- 药物研发.
7.4 安防monitor
- exceptionbehavior检测.
- 入侵检测.
- 人群monitor.
- 车牌识别.
- 视频摘要.
7.5 零售行业
- 商品识别 and classification.
- 货架monitor.
- 顾客behavioranalysis.
- 自助结账.
- library存management.
7.6 农业
- 农作物病虫害检测.
- 作物生 long status监测.
- 收获机器人.
- 土壤analysis.
- 农业无人机.
7.7 工业
- quality检测.
- defect检测.
- 工业机器人视觉引导.
- produce过程monitor.
- 设备maintenance预测.
7.8 娱乐 and 媒体
- graph像processing and 增强.
- 视频编辑 and 特效.
- 虚拟现实 and 增强现实.
- content recommendations.
- 游戏Development.
8. 互动练习
练习 1: graph像processing实践
- usingOpenCVimplementationbasic graph像processingoperation.
- 尝试不同 graph像滤波, edge缘检测 and 阈值化method.
- 比较不同parameter for processing结果 影响.
- creation一个 simple graph像processing pipeline.
练习 2: graph像classification
- usingPyTorch or TensorFlow and 预训练modelforgraph像classification.
- test不同class别 graph像.
- analysismodel 预测结果.
- 尝试微调model以improvingspecificclass别 classification准确率.
练习 3: 目标检测
- using预训练 目标检测model (such asYOLO, Faster R-CNNetc.) .
- testmodel in 不同场景 under 检测效果.
- analysismodel 检测精度 and 速度.
- 尝试usingmodelfor实时目标检测.