OpenCV 学习记录(1)

2021/11/3 23:40:56

本文主要是介绍OpenCV 学习记录(1),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

调用本地图像进行灰度处理

import cv2

img = cv2.imread('D:\\learn\\python\\t01\\asd.jpg',cv2.IMREAD_GRAYSCALE)#路径为处理的文件路径
cv2.imshow("result", img )#“result”为窗口名 img为图像
#cv2.imwrite("asd.png",img) #存储名为asd.png的照片
cv2.waitKey(0)等待时间
#cv2.waitKey(1000)#等待1s (毫秒单位)
cv2.destroyWindow

封装为函数

def cv_show(name,img)
	cv2.imshow(name,img)
	cv2.waitKey(0)等待时间
	#cv2.waitKey(1000)等待1s (毫秒单位)
	cv2.destroyWindow

调用摄像头灰度

import cv2

vc = cv2.VideoCapture(0)#0,1为摄像头设备号,也可换“xxx.mp4”记得调整cv2.waitKey()
if vc.isOpened():
    open, frame = vc.read()#将读取到的
else:
    open = False

while open:
    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) & 0xFF ==27:
            break
vc.release()
cv2.destroyWindow()


这篇关于OpenCV 学习记录(1)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程