入坑python-opencv ,实现摄像头读取

import cv2
import skimage
from skimage.util.dtype import convert



vc = cv2.VideoCapture(0)
# 加载摄像头,进行读取,此API也可以加载本地的视频  
if vc.isOpened():
    # 来保证读取成功
    oepn, frame = vc.read()
else:
    open = False

while open:
    
    ret, frame = vc.read()
    if frame is None:
        break
    if ret == True:
#   将读取的照片信息进行颜色的转化 0为灰色,1为RGB
# 其实为了在图像上做处理而预备的
        gray = cv2.cvtColor(frame, 1)

        # noise_img = skimage.util.random_noise(gray, mode="salt")
        gray = skimage.util.random_noise(gray, mode='gaussian')
        # gray = cv2.GaussianBlur(gray, ksize=3)
        cv2.imshow('result', gray)
# 直接1 ms进行更细图像  知道按esc
        if cv2.waitKey(1) & 0xFF == 27:
            break


vc.release()
cv2.destroyAllWindows()
cv2.imshow()

 

你可能感兴趣的:(物联网)