本文为9月14日计算机视觉基础学习笔记——基本图像处理,分为四个章节:
二值图像:
灰度图:
RGB:
图像采集过程:
实际上是对矩阵的处理。
cap = cv.VideoCapture(0)
img = cv.imread("lena.jpg")
img_RGB = cv.cvtColor(img, cv.COLOR_BGR2RGB)
print(img.shape)
>>> (722, 726, 3)
# Range of Interest
roi = img_RGB[100:200, 300:400]
plt.imshow(img_RGB)
plt.imshow(roi)
import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
img0 = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]])
print(img0)
print(img0.shape)
print("img0 size = {}, {}".format(img0.shape[0], img0.shape[1]))
>>> [[0 0 1]
[0 1 0]
[1 0 0]]
>>> (3, 3)
>>> img0 size = 3, 3
# 灰度图片
plt.imshow(img0, cmap="gray")
# 彩色图片
plt.imshow(img0)
img_hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
plt.imshow(img_hsv)
# 肤色检测
# 二值化:非0即最大值。
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
ret, thresh = cv.threshold(img_gray, 128, 200, cv.THRESH_BINARY)
plt.imshow(thresh)
img_blur = cv.GaussianBlur(img_RGB, (11, 11), 1, 0) # 高斯模糊
plt.imshow(img_blur)
wm = cv.imread("UoB.png")
wm = cv.resize(wm, (300, 300))
wm = cv.cvtColor(wm, cv.COLOR_BGR2RGB)
wm = wm - 255
img1 = cv.resize(img_RGB, (300, 300))
print(wm.shape)
>>> (300, 300, 3)
plt.imshow(cv.add(wm, img1))
plt.imshow(cv.addWeighted(wm, 0.9, img1, 0.5, 0))