在第一次和opencv接觸后,感觸頗多,
anaconda安裝cv2程序坎坷,折騰了兩個小時,
最后的程式還出現了個神秘錯誤,不過不影響運行,本小白就寫出來記錄下,
本程式作用介紹:對視頻按照幀數分割成圖片,
下面是代碼:
import cv2
import os
video_name = '02.mp4'
def save_img():
video_path = 'C:\\Users\\jhon smis\\Desktop\\'
videos = os.listdir(video_path)
for video_name in videos:
file_name = video_name.split('.')[0]
folder_name = video_path + file_name
os.makedirs(folder_name, exist_ok=True)
vc = cv2.VideoCapture(video_path + '/' + video_name)
c = 0
rval = vc.isOpened()
frames= 1
count = 1
while rval:
c = c + 1
rval, frame = vc.read()
pic_path = 'G:\\TUPIAN\\Winter Storm Xylia Time-l-VideoIndirelim.com\\'
if rval:
if frames%10 == 0:
cv2.imwrite(pic_path + str(c) + '.jpg', frame)
cv2.waitKey(1)
count += 1
frames= frames+1
else:
break
vc.release()
print('save_success')
print(folder_name)
程式運行時輸出均正常
下面是報錯
[ERROR:0] VIDEOIO(cvCreateFileCapture_Images(filename.c_str())): raised OpenCV exception:
OpenCV(3.4.14) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-ta6q0f5f\opencv\modules\videoio\src\cap_images.cpp:246: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): C:\Users\jhon smis\Desktop\/Origin.lnk in function 'cv::icvExtractPattern'
[ERROR:0] VIDEOIO(cvCreateFileCapture_Images(filename.c_str())): raised OpenCV exception:
OpenCV(3.4.14) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-ta6q0f5f\opencv\modules\videoio\src\cap_images.cpp:246: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): C:\Users\jhon smis\Desktop\/Rockstar Games Launcher.lnk in function 'cv::icvExtractPattern'
錯誤表現:
會把我桌面上的檔案一個一個做出對應的空檔案夾
如下圖所示:


我的猜測:現在完全不確定是什么問題了,剛剛一下出現了一大堆空檔案夾
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/332187.html
標籤:其他
