OpenCV:修订间差异
(创建页面,内容为“OpenCV(Open Source Computer Vision Library),计算机视觉库,可以实时图像处理,识别。OpenCV支持多种编程语言,如C++,Python,Java等,…”) |
无编辑摘要 |
||
(未显示同一用户的5个中间版本) | |||
第1行: | 第1行: | ||
OpenCV(Open Source Computer Vision Library) | OpenCV(Open Source Computer Vision Library),一个开源的计算机视觉库,可以实时图像处理,识别。OpenCV支持多种编程语言,如[[C++]],[[Python]],[[Java]]等,并且可以在不同的平台上使用。 | ||
==简介== | ==简介== | ||
第13行: | 第13行: | ||
===OpenCV-Python 安装=== | ===OpenCV-Python 安装=== | ||
OpenCV-Python是OpenCV的Python API。 | OpenCV-Python是OpenCV的Python API。 | ||
使用[[pip]]安装预构建的仅限 CPU 的 OpenCV 包,如果需要启用其他模块(例如 CUDA),需要手动安装。OpenCV-Python预构建4个软件包,其中无头模式,不包含任何用户界面,适用服务器环境(如 Docker、云环境等)。 | |||
<syntaxhighlight lang="bash" > | |||
# 主模块包 | |||
pip install opencv-python | |||
# 完整包,包含主模块和 contrib/extra 模块 | |||
# pip install opencv-contrib-python | |||
# 无头主模块包 | |||
# pip install opencv-python-headless | |||
# 无头完整包,包含主模块和 contrib/extra 模块 | |||
# install opencv-contrib-python-headless | |||
</syntaxhighlight> | |||
{{了解更多 | {{了解更多 | ||
|[https://github.com/opencv/opencv-python opencv-python 源代码] | |||
|[https://docs.opencv.org/4.x/da/df6/tutorial_py_table_of_contents_setup.html OpenCV 文档:OpenCV-Python简介] | |[https://docs.opencv.org/4.x/da/df6/tutorial_py_table_of_contents_setup.html OpenCV 文档:OpenCV-Python简介] | ||
}} | }} | ||
== | ==快速入门== | ||
===图片转换=== | |||
<syntaxhighlight lang="python" > | |||
import cv2 | |||
img = cv2.imread("test.jpg") # 读取文件 | |||
cv.imshow("Display Title", img) # 显示 | |||
cv.imwrite("test.png", img) # 保存图片 | |||
</syntaxhighlight> | |||
{{了解更多 | |||
|[https://docs.opencv.org/4.x/db/deb/tutorial_display_image.html OpenCV 4.x 文档:显示图片] | |||
}} | |||
==图片处理== | |||
{| class="wikitable" style="width: 100%; | |||
! 名称 | |||
! 描述 | |||
! 示例 | |||
|- | |||
|读取保存图片 imread() | |||
| | |||
| | |||
|- | |||
| | |||
| | |||
| | |||
| | |||
|- | |||
| 改变尺寸 resize() | |||
| | |||
| <syntaxhighlight lang="python" > | |||
import cv2 | |||
img = cv2.imread(r"test.jpg") | |||
width = 1200 | |||
height = int(width*img.shape[1]/img.shape[0]) | |||
img_1200 = cv2.resize(img, (width,height), interpolation=cv2.INTER_CUBIC) | |||
</syntaxhighlight> 宽度调整为1200px,高度随比例。 | |||
|- | |||
|压缩图片 | |||
| | |||
| <syntaxhighlight lang="python" > | |||
cv2.imwrite('out_80.jpg', img, [cv2.IMWRITE_JPEG_QUALITY,80]) | |||
cv2.imencode('.jpg', img, [cv2.IMWRITE_JPEG_QUALITY,80])[1].tofile(r'D:\测试\out_80.jpg') | |||
</syntaxhighlight> | |||
|- | |||
| | |||
| | |||
| | |||
|} | |||
==视频分析== | |||
==对象检测== | |||
==中文问题== | |||
imread()和imwrite()读取保存文件时候,路径中有中文字符会报错,使用imdecode替代。 | |||
<syntaxhighlight lang="python" > | |||
import cv2 | |||
import numpy as np | |||
file= r'D:\测试\图片.jpg' | |||
img = cv2.imdecode(np.fromfile(file=file , dtype=np.uint8), cv2.IMREAD_COLOR) | |||
file_output = r'D:\测试\图片输出.jpg' | |||
cv2.imencode(ext='.jpg', img=img)[1].tofile(file_output) | |||
</syntaxhighlight> | |||
==资源== | ==资源== | ||
第25行: | 第110行: | ||
* OpenCV 文档:https://docs.opencv.org/ | * OpenCV 文档:https://docs.opencv.org/ | ||
* OpenCV 源代码:https://github.com/opencv/opencv | * OpenCV 源代码:https://github.com/opencv/opencv | ||
* opencv-python 源代码:https://github.com/opencv/opencv-python | |||
* OpenCV 源代码:https://sourceforge.net/projects/opencvlibrary/ | * OpenCV 源代码:https://sourceforge.net/projects/opencvlibrary/ | ||
* OpenCV 论坛:https://forum.opencv.org/ | * OpenCV 论坛:https://forum.opencv.org/ | ||
===网站=== | ===网站=== |
2023年4月26日 (三) 06:48的最新版本
OpenCV(Open Source Computer Vision Library),一个开源的计算机视觉库,可以实时图像处理,识别。OpenCV支持多种编程语言,如C++,Python,Java等,并且可以在不同的平台上使用。
简介
时间轴
安装
OpenCV 安装
了解更多 >> OpenCV 文档:安装概览
OpenCV-Python 安装
OpenCV-Python是OpenCV的Python API。
使用pip安装预构建的仅限 CPU 的 OpenCV 包,如果需要启用其他模块(例如 CUDA),需要手动安装。OpenCV-Python预构建4个软件包,其中无头模式,不包含任何用户界面,适用服务器环境(如 Docker、云环境等)。
# 主模块包
pip install opencv-python
# 完整包,包含主模块和 contrib/extra 模块
# pip install opencv-contrib-python
# 无头主模块包
# pip install opencv-python-headless
# 无头完整包,包含主模块和 contrib/extra 模块
# install opencv-contrib-python-headless
快速入门
图片转换
import cv2
img = cv2.imread("test.jpg") # 读取文件
cv.imshow("Display Title", img) # 显示
cv.imwrite("test.png", img) # 保存图片
了解更多 >> OpenCV 4.x 文档:显示图片
图片处理
名称 | 描述 | 示例 | |
---|---|---|---|
读取保存图片 imread() | |||
改变尺寸 resize() | import cv2
img = cv2.imread(r"test.jpg")
width = 1200
height = int(width*img.shape[1]/img.shape[0])
img_1200 = cv2.resize(img, (width,height), interpolation=cv2.INTER_CUBIC)
| ||
压缩图片 | cv2.imwrite('out_80.jpg', img, [cv2.IMWRITE_JPEG_QUALITY,80])
cv2.imencode('.jpg', img, [cv2.IMWRITE_JPEG_QUALITY,80])[1].tofile(r'D:\测试\out_80.jpg')
| ||
视频分析
对象检测
中文问题
imread()和imwrite()读取保存文件时候,路径中有中文字符会报错,使用imdecode替代。
import cv2
import numpy as np
file= r'D:\测试\图片.jpg'
img = cv2.imdecode(np.fromfile(file=file , dtype=np.uint8), cv2.IMREAD_COLOR)
file_output = r'D:\测试\图片输出.jpg'
cv2.imencode(ext='.jpg', img=img)[1].tofile(file_output)
资源
官网
- OpenCV 官网:https://opencv.org/
- OpenCV 文档:https://docs.opencv.org/
- OpenCV 源代码:https://github.com/opencv/opencv
- opencv-python 源代码:https://github.com/opencv/opencv-python
- OpenCV 源代码:https://sourceforge.net/projects/opencvlibrary/
- OpenCV 论坛:https://forum.opencv.org/