结合Opencv3.0读取视频时,出现报错:C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:11111: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
1 # -*- coding: utf-8 -*-
2 """
3 Created on Fri Mar 23 14:47:20 2018
4
5 @author: Tanqiqi
6 """
7
8 import numpy as np
9 import cv2
10
11 cap = cv2.VideoCapture('1.avi') #读入视频
12 c=1
13 while(cap.isOpened()):
14 ret, frame = cap.read() #分解为一帧一帧图像
15 if ret == True: #记得要对视频是否处理完成做判断
16 gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #转换为灰度图像
17 cv2.imshow('frame',gray) #显示标记后的图像
18 cv2.imwrite('image/'+str(c) + '.jpg',frame) #存储为图像
19 c = c+1
20 else:
21 break
22
23 if cv2.waitKey(1) & 0xFF == ord('q'):
24 break
25
26
27 cap.release()
28 cv2.destroyAllWindows()
29
30