NameError: name 'cap' is not defined
.
import cv2
import os
dir_path = '/home/ji/YouTubeClips'
for name in os.listdir(dir_path):
#count=count+1
video_id = name.split('.')[0]
cap = cv2.VideoCapture(0)
success,image = vidcap.read()
count = 0
success = True
total_frames = vidcap.get(1)
single_frame = '/home/jeevitha/2017611005/frame_single/image/'+video_id+'.jpg'
if not (os.path.isfile(single_frame) ):
video_file_path=os.path.join(dir_path, name)
print(video_file_path)
if (cap.isOpened()== False):
print("Error opening video stream or file")
total = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
if success:
cv2.imwrite(video_id+'.jpg',image)
vidcap.set(cv2.CAP_PROP_POS_MSEC,(count*65000)) # added this line
# save frame as JPEG file
to solve this issue
problem: you copy / pasted snippets without any understanding of it
have a look here
vidcap.set(cv2.CAP_PROP_POS_MSEC,(count*65000)) # added this line
try to find out, why this is wrong (or -- too late)
you need to open a
cv.VideoCapture
instance per file you want to read.(and no, i won't write your program. you've done enough harm with copy / paste already. now it's time to understand, what you're doing ;)
65000 is a seconds value of frame in video
yea, but there's no
vidcap
, nocap
and nosuccess
defined ever --you never even tried to understand, what you're doingno use opening a webcam, when you want to use video files
please stop that blind copy / paste approach -- you'll get nowwhere like this