- 色彩空间转换
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
cv.imshow("gray", gray)
hsv = cv.cvtColor(image, cv.COLOR_BGR2HSV)
cv.imshow("hsv", hsv)
yuv = cv.cvtColor(image, cv.COLOR_BGR2YUV)
cv.imshow("yuv", yuv)
Ycrcb = cv.cvtColor(image, cv.COLOR_BGR2YCrCb)
cv.imshow("ycrcb", Ycrcb)
- 视频加载读取
capture = cv.VideoCapture("D:/vcprojects/images/video_006.mp4")
while(True):
ret, frame = capture.read()
if ret == False:
break;
hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
lower_hsv = np.array([37, 43, 46])
upper_hsv = np.array([77, 255, 255])
mask = cv.inRange(hsv, lowerb=lower_hsv, upperb=upper_hsv)
dst = cv.bitwise_and(frame, frame, mask=mask)
cv.imshow("video", frame)
cv.imshow("mask", dst)
c = cv.waitKey(40)
if c == 27:
break
- mask = cv.inRange(hsv, lowerb=lower_hsv, upperb=upper_hsv)#inRange函数提取某一色彩空间域的图像,通过调节图像颜色信息(H)、饱和度(S)、亮度(V)区间选择我们需要的图像区域
- 算数运算api
dst = cv2.add(m1,m2)
dst = cv2.subtract(m1,m2)
dst = cv2.multiply(m1,m2)
dst = cv2.divide(m1,m2)
- 逻辑运算api
dst = cv2.bitwise_and(m1,m2) # 与运算
dst = cv2.bitwise_or(m1, m2) # 或运算
dst = cv2.bitwise_not(m1) # 非运算
- 亮度对比
def contract_brightness_demo(image,c,b): # 亮度对比
h, w,ch = image.shape
blank = np.zeros([h,w,ch],image.dtype)
dst = cv2.addWeighted(image,c,blank,1-c,b)
cv2.imshow("con_b",dst)
``
7. 均值/方差
def others(m1,m2):
m1 = cv2.mean(m1) #均值
m2 = cv2.mean(m2)
m1,dev1 = cv2.meanStdDev(m1) #方差
m2, dev1 = cv2.meanStdDev(m2)
print(m1,m2)
``
- CPU运算时间统计
t1 = cv.getTickCount()
creat_image()
t2 = cv.getTickCount()
print("time:%s ms"%((t2-t1)/cv.getTickFrequency())*1000)