本文目錄一覽:
- 1、python OpenCV視頻拆分圖片代碼
- 2、python用OpenCV轉卡通照片報錯,好像是pyrdown的使用有問題?
- 3、python怎麼實現文件格式的轉換
- 4、如何用python實現視頻關鍵幀提取並保存為圖片?
- 5、如何用python實現視頻關鍵幀提取並保存為圖片
python OpenCV視頻拆分圖片代碼
# coding:utf-8
import cv2
import numpy as np
import os
print(“1”)
vc = cv2.VideoCapture(“123.mp4”)
C = 1
print(“2”)
if vc.isOpened():
rVal, frame = vc.read()
else:
print(“3”)
rVal = False
while rVal:
print(C)
if C % 1000 == 0: # every 5 fps write frame to img
path=’./image/’+str(C)+’.jpg’
cv2.imwrite(path, frame)
# cropped001 = frame2[0:300,300:600] #y change from 0 to 300 x change from 300 to 600
# cv2.im write(‘./cropped/’+str(c)+’001.jpg’,cropped001)
print(C)
cv2.waitKey(1)
C = C + 1
vc.release()
python用OpenCV轉卡通照片報錯,好像是pyrdown的使用有問題?
你這個是pyrdown函數使用的時候,操作一次一個 M x N 的圖像就變成了一個 M/2 x N/2 的圖像。像素不是2的整數倍造成pyrup函數使用時像素出現不對等
python怎麼實現文件格式的轉換
1. 如果是文檔類轉換的話, 可以藉助 pypandoc模塊(pip install pypandoc)
import pypandoc
out = pypandoc.convert_file(‘a.txt’, ‘docx’, outputfile = ‘a.docx’) # 轉為docx
2. 如果是圖片或者視頻類的轉化的話, 可以使用 opencv
import cv2
img = cv2.imread(‘a.jpg’)
out = cv2.imwrite(‘a.png’, img) # jpg轉png
如何用python實現視頻關鍵幀提取並保存為圖片?
參考代碼如下:
import
cv2
vc
=
cv2.VideoCapture(‘Test.avi’)
#讀入視頻文件
c=1
if
vc.isOpened():
#判斷是否正常打開
rval
,
frame
=
vc.read()
else:
rval
=
False
timeF
=
1000
#視頻幀計數間隔頻率
while
rval:
#循環讀取視頻幀
rval,
frame
=
vc.read()
if(c%timeF
==
0):
#每隔timeF幀進行存儲操作
cv2.imwrite(‘image/’+str(c)
+
‘.jpg’,frame)
#存儲為圖像
c
=
c
+
1
cv2.waitKey(1)
vc.release()
如何用python實現視頻關鍵幀提取並保存為圖片
import cv2
vc = cv2.VideoCapture(‘Test.avi’) #讀入視頻文件
c=1
if vc.isOpened(): #判斷是否正常打開
rval , frame = vc.read()
else:
rval = False
timeF = 1000 #視頻幀計數間隔頻率
while rval: #循環讀取視頻幀
rval, frame = vc.read()
if(c%timeF == 0): #每隔timeF幀進行存儲操作
cv2.imwrite(‘image/’+str(c) + ‘.jpg’,frame) #存儲為圖像
c = c + 1
cv2.waitKey(1)
vc.release()
原創文章,作者:SGGYG,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/128678.html