OpenCV学习笔记:
第一节课:
- RGB颜色通道:所有彩图都是三颜色图
- 0~255,亮度从黑色到白色
- R:红, G:绿, B:蓝
- 而对于一个灰度图,不需要RGB颜色通道
import cv2
import numpy as np
img = cv2:imread('路径', 参数)
cv2.imshow('名称(随便取)', img)
cv2.waitKey(参数)
cv2.destoryALLWindows()
img.shape[参数]
cv2.imwrite('路径+名称:如./picture/img.jpg:',img)
vc = cv2.VideoCapture(参数)
第二节课:
vc = cv2.VideoCapture(参数)
if vc.isOpend():
ret, frame = vc.read()
else:
ret = False
while ret:
ret, frame = vc.read()
if frame is None:
break
if ret = True:
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('result', gray)
if cv2.waitKey(10) & OxFF == 27:
break
vc.release()
cv2.destoryALLWindows()
第三节课:
img = cv2.imread()
cut = img[a:b, c:d]
cv2.imshow('cut', cut)
b,g,r = cv2.split(img)
img = cv2.merge(b,g,r)
cur_img = img.copy()
cur_img[:,:,0] = 0
cur_img[:,:,1] = 0
cv2.imshow('R', cur_img)
第四节课:
(top_size, bottom_size, left_size, right_size) = (a,b,c,d)
replace = cv2.copyMakeBorder(img, top_size, bottom_size, left_size, right_size, cv2.方式)
img = img + n
img1 + img2
cv2.add(img1, img2)
img = cv2.resize(img, (x, y))
img = cv2.resize(img, (0,0), fx = a, fy = b)
第五节课:
ret, dst = cv2.threshoid(src, thresh, maxval, type)
第六,七节课:
blur = cv2.blur(img, (x, x))
box = cv2.boxFilter(img, -1, (x,x), normalize = Ture)
gaussian = cv2.GaussianBlur(img, (x,x), 1)
median = cv2.medianBlur(img, x)
res = np.hstack(vstaack)(blur,gaussian,median)
cv2.imshow('all', res)
cv2.waitKey(0)
cv2.destoryALLWindow()
第八节课:
kernel = np.ones((x,x), np.uint8)
erosion = cv2.erode(img, kernel, iterations = y)
cv2.imshow('erosion', erosion)
cv2.waitKey(0)
cv2.destoryALLWindow()
第九节课:
kernel = np,ones((x,x), np.unit8)
dilate = cv2.dilate(img, kernel, iterations = y)
cv2.imshow('dilate', dilate)
cv2.waitKey(0)
cv2.destoryALLWindow()
第十节课:
kernel = np,ones((x,x), np.unit8)
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
kernel = np,ones((x,x), np.unit8)
closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)
第十一节课:
kernel = np,ones((x,x), np.unit8)
gradient = cv2.morphologyEx(img, cv2.MORPH_GRADIENT, kernel)
cv2.imshow('gradient', gradient)
cv2.waitKey(0)
cv2.destoryALLWindow()
第十二节课:
kernel = np,ones((x,x), np.unit8)
tophat = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel)
cv2.imshow('tophat', tophat)
cv2.waitKey(0)
cv2.destoryALLWindow()
kernel = np,ones((x,x), np.unit8)
blackhat = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel)
cv2.imshow('', blackhat)
cv2.waitKey(0)
cv2.destoryALLWindow()