在第一次和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:UsersrunneradminAppDataLocalTemppip-req-build-ta6q0f5fopencvmodulesvideoiosrccap_images.cpp:246: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): C:Usersjhon smisDesktop/Origin.lnk in function 'cv::icvExtractPattern' [ERROR:0] VIDEOIO(cvCreateFileCapture_Images(filename.c_str())): raised OpenCV exception: OpenCV(3.4.14) C:UsersrunneradminAppDataLocalTemppip-req-build-ta6q0f5fopencvmodulesvideoiosrccap_images.cpp:246: error: (-5:Bad argument) CAP_IMAGES: can't find starting number (in the name of file): C:Usersjhon smisDesktop/Rockstar Games Launcher.lnk in function 'cv::icvExtractPattern'
错误表现:
会把我桌面上的文件一个一个做出对应的空文件夹
如下图所示:
我的猜测:现在完全不确定是什么问题了,刚刚一下出现了一大堆空文件夹
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)