引言
此系列博客记录 网易云课堂 python + openCV图像处理课程的学习过程。
本篇博客将介绍 读取、显示、保存图像,读取、修改 像素值(openCV 与 numpy) 三个部分。
介绍
OpenCV (Open Source Computer Vision Library) is released under a BSD license and hence it’s free for both academic and commercial use. It has C++, Python and Java interfaces and supports Windows, Linux, Mac OS, iOS and Android.
OpenCV was designed for computational efficiency and with a strong focus on real-time applications. Written in optimized C/C++, the library can take advantage of multi-core processing.
Enabled with OpenCL(一个为异构平台编写程序的框架), it can take advantage of the hardware acceleration of the underlying heterogeneous compute platform.
图像基础
1、图像都是由像素构成的,在同等面积下,像素点越多,图像越细腻。
2、图像分类:
- 二值图像:图像只有 黑、白 两种颜色(像素点 0 或 1)
- 灰度图像:图像只有 黑、白、灰 三种颜色(像素点 0 - 255,其中 0 为黑色,255 为白色,1-254 之间均为灰色)
- RGB图像:彩色图像
tips: 二值和灰度图像 均为 单通道,RGB图像 为 三通道。
3、彩色图像(RGB):由 红、绿、蓝 三色 按照某种比例混合而成的。
- 比如:
(255,182,193)
表示浅粉红色,更常用的16进制 -#FFB6C1
4、彩色图像(BGR):openCV
库 专用,顺序为 蓝、绿、红 。
代码
1、读取、显示、保存图像
# -*- coding: utf-8 -*-
import cv2 # 导入 openCV 库
i = cv2.imread(r"C:\workspace\python\openCV\test.jpg") # 读取
cv2.imshow("Demo",i) # 显示
cv2.waitKey(0) # 窗口等待
cv2.destroyAllWindow