# -*- coding: utf-8 -*- """ Created on Tue Sep 11 16:35:29 2018 @author: 车路历程 """ import cv2 from skimage import io import os # 视频所在文件夹的路径位置 videos_path = 'F:/self/0' # 从视频文件夹中获取各个视频的名字 videos_name = os.listdir(videos_path) # 视频帧图片的起始编号 a = 0 # 遍历所有的视频 for i in videos_name: # 获取每个视频的路径 video_path = os.path.join(videos_path, i) # 如果遇见文件夹就跳过 if os.path.isdir(video_path): continue camera = cv2.VideoCapture("E:/video/7.mp4") # 参数0表示第一个摄像头 # 判断视频是否打开 if (camera.isOpened()): print('Open') else: print('摄像头未打开') # 测试用,查看视频size size = (int(camera.get(cv2.CAP_PROP_FRAME_WIDTH)), int(camera.get(cv2.CAP_PROP_FRAME_HEIGHT))) print('size:'+repr(size)) while True: # 读取视频流 grabbed, frame_lwpCV = camera.read() # 当从视频中读取不到视频帧就退出 if frame_lwpCV is None: break # 将彩色图片转化为灰度图 gray_lwpCV = cv2.cvtColor(frame_lwpCV, cv2.COLOR_BGR2GRAY) # 进行滤波处理 gray_lwpCV = cv2.GaussianBlur(gray_lwpCV, (21, 21), 0) # 保存图片 io.imsave("E:/all_picture/final_picture/%s-0.jpg"%a, frame_lwpCV) a += 1 # 显示图片 cv2.imshow('contours', frame_lwpCV) key = cv2.waitKey(1) & 0xFF # 按'q'健退出循环 if key == ord('q'): break # When everything done, release the capture camera.release() cv2.destroyAllWindows()