1 # 视频分解图片 2 # 1.load 2.info 3.parse 4.imshow 5.imwrite 3 import cv2 4 cap = cv2.VideoCapture("./pop/pop.mp4") 5 isOpened = cap.isOpened # 判断是否可以打开 6 print(isOpened) 7 fps = cap.get(cv2.CAP_PROP_FPS) # 帧率 8 width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # 获取宽,高 9 heigth = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) 10 print(fps,width,heigth) 11 i = 0 12 while(isOpened): 13 if i==10: 14 break 15 else: 16 i = i+1 17 (flag,frame) = cap.read() # 读取每一种的 flag(表示是否读取成功),frame(表示内容) 18 fileName = 'popimg'+str(i)+'.jpg' # pop为写入的文件夹地址,img表示写入的名称 19 print(fileName) 20 if flag == True: # 如果读取图片成功 21 cv2.imwrite(fileName,frame,[cv2.IMWRITE_JPEG_QUALITY,100]) # 写入图片 fileName:图片名称,frame:图片·内容;最后一个表示写入的图片格式 22 img = cv2.imread(fileName,1) 23 imgInfo = img.shape 24 print(imgInfo) 25 H = imgInfo[0] 26 W = imgInfo[1] # 获取图片的宽高 27 mode = imgInfo[2] 28 changeH = int(H*0.1) 29 changeW = int(W*0.1) 30 print(changeH) 31 print(changeW) 32 new_img = cv2.resize(img,(changeW,changeH),cv2.INTER_AREA) # img图片对象,使用插值算法改变图片大小 33 cv2.imwrite(fileName, new_img) # 写入重新生成的图片对象 34 print('缩放完成!') 35 print('写入图片结束!')
# 视频分解图片
# 1.load 2.info 3.parse 4.imshow 5.imwrite
import cv2
cap = cv2.VideoCapture("./pop/pop.mp4")
isOpened = cap.isOpened # 判断是否可以打开
print(isOpened)
fps = cap.get(cv2.CAP_PROP_FPS) # 帧率
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) # 获取宽,高
heigth = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
print(fps,width,heigth)
i = 0
while(isOpened):
if i==10:
break
else:
i = i+1
(flag,frame) = cap.read() # 读取每一种的 flag(表示是否读取成功),frame(表示内容)
fileName = 'popimg'+str(i)+'.jpg' # pop为写入的文件夹地址,img表示写入的名称
print(fileName)
if flag == True: # 如果读取图片成功
cv2.imwrite(fileName,frame,[cv2.IMWRITE_JPEG_QUALITY,100]) # 写入图片 fileName:图片名称,frame:图片·内容;最后一个表示写入的图片格式
img = cv2.imread(fileName,1)
imgInfo = img.shape
print(imgInfo)
H = imgInfo[0]
W = imgInfo[1] # 获取图片的宽高
mode = imgInfo[2]
changeH = int(H*0.1)
changeW = int(W*0.1)
print(changeH)
print(changeW)
new_img = cv2.resize(img,(changeW,changeH),cv2.INTER_AREA) # img图片对象,使用插值算法改变图片大小
cv2.imwrite(fileName, new_img) # 写入重新生成的图片对象
print('缩放完成!')
print('写入图片结束!')